79 of 119 menu

Selector empty

The :empty selector selects elements that have no descendants (that is, empty elements, which contain neither an element nor text).

Syntax

Getting empty elements:

$(':empty');

Example

We have a table table with a green background, let's find the cells td that don't have any text or element inside them and color them gray:

<table> <tr><td>aaa</td><td></td></tr> <tr><td>bbb</td><td></td></tr> <tr><td>ccc</td><td></td></tr> </table> table { border: 1px; } td { width: 40px; background: green; } $('td:empty').css({background: '#ccc'});

See also

  • selector parent,
    which selects parent elements
  • method css,
    which allows you to get and change the CSS styles of an element
byenru