:emptyS2C Home « Selectors « :empty

UI element states pseudo-class match selector.

Shorthand version  $(':empty')


The :empty selector, selects all childless elements.

Text nodes count as children.

Opposite of the :parent selector.

By definition, self closing tags such as <br> and <i> are childless.

This selector is the inverse of :parent.

If this selector is not preceded by another selector, the universal selector ("*") is implied and so the whole DOM will be searched. Use another selector as in the example below to narrow the search and improve performance.


Signature Description
jQuery(':empty')UI element states pseudo-class match





:empty ExampleTop

Selects all childless elements.

The following example will check for empty input elements and set a yellow background when the button below is clicked.

  $('#btn21').on('click', function() {
    $("input:empty").css('backgroundColor', 'yellow'); 

Please fill in the form:

Your Information

 Enter your name:

Press the button below to action the above code: