empty selector
Description: Select all elements that have no children (including text nodes).
version added: 1.0jQuery( ":empty" )
This is the inverse of :parent
.
One important thing to note with :empty (and :parent) is that child elements include text nodes.
The W3C recommends that the <p>
element have at least one child node, even if that child is merely text (see https://www.w3.org/TR/html401/struct/text.html#edef-P). Some other elements, on the other hand, are empty (i.e. have no children) by definition: <input>, <img>, <br>, and <hr>, for example.
Example:
Finds all elements that are empty - they don't have child elements or text.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |