{"name":"empty","type":"selector","title":":empty Selector","deprecated":null,"removed":null,"desc":"Select all elements that have no children (including text nodes).","categories":["selectors/content-filter-selector","version/1.0"],"entries":[{"return":"","signatures":{"added":"1.0"},"examples":{"desc":"Finds all elements that are empty - they don't have child elements or text.","code":"\n$( \"td:empty\" )\n .text( \"Was empty!\" )\n .css( \"background\", \"rgb(255,220,200)\" );\n","css":"\n td {\n text-align: center;\n }\n","html":"\n
| TD #0 | |
| TD #2 | |
| TD#5 |
This is the inverse of :parent.
One important thing to note with :empty (and :parent) is that child elements include text nodes.
\nThe W3C recommends that the <p> element have at least one child node, even if that child is merely text (see http://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.