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:

javascript$(':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:

html<table>
  <tr><td>aaa</td><td></td></tr>
  <tr><td>bbb</td><td></td></tr>
  <tr><td>ccc</td><td></td></tr>
</table>
csstable {
  border: 1px;
}
  
td {
  width: 40px;
  background: green;
} 
javascript$('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