Use the :empty
pseudo to do the trick, e.g. to select ALL elements with no children (including no text nodes... nothing):
*:empty
Delan Azabani
2010-05-18 10:46:22
Use the :empty
pseudo to do the trick, e.g. to select ALL elements with no children (including no text nodes... nothing):
*:empty
I don't think this can be done with CSS alone. You would have to loop through all elements testing for a false return on hasChildNodes()
. It would be sloppy and not something I would recommend.
As a text node is also a node for CSS you cannot do it with any CSS selector. Doing it with JavaScript you should first select all nodes with only one child and than test if it is only a text node.