:empty JQ Home  <<  Selectors  <<  :empty

UI element states pseudo-class match selector.

Shorthand version $(':empty')

Description

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 <img> 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.

Syntax

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

Parameters

None.

Return

N/A.

:empty Example Selectors  <<  Top

Selects all childless elements.

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




$(function(){
  $('#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:

Related Tutorials

jQuery Basic Tutorials - Lesson 3 - CSS Selectors