parent selector
Description: Select all elements that are the parent of another element, including text nodes.
jQuery(':parent')
version added: 1.0
This is the inverse of :empty.
One important thing to note regarding the use of :parent (and :empty) 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 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.
Examples
Finds all tds with children, including text.Full source:
<!DOCTYPE html> <html> <head> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready(function(){ $("td:parent").fadeTo(1500, 0.3); }); </script> <style> td { width:40px; background:green; } </style> </head> <body> <table border="1"> <tr><td>Value 1</td><td></td></tr> <tr><td>Value 2</td><td></td></tr> </table> </body> </html>
Was this information helpful?

