:parent Selector

Select all elements that have at least one child node (either an element or text).

.parent()

This is the inverse of :empty.

One important thing to note regarding the use of :parent (and :empty) is that child nodes 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.

To obtain the parents or ancestors of an existing jQuery set, see the .parent() and .parents() methods.

Finds all tds with children, including text.

JS
<table border="1">
  <tr>
    <td>Value 1</td>
    <td></td>
  </tr>
  <tr>
    <td>Value 2</td>
    <td></td>
  </tr>
</table>
CSS
td {
  width: 40px;
  background: green;
}
HTML
$("td:parent").fadeTo(1500, 0.3);
DEMO

Looking for a Web Developer?

👋

Hi! I'm Basti, author of this site. If you are looking for a web developer with 15+ years of experience, holla at me!

Be it the good 'ol jQuery, vanilla JS or modern frameworks like Vue and Svelte, front- or backend, I can help you.

Just write me at jobs@jqapi.com :)