:empty
S2C Home « Selectors « :empty
UI element states pseudo-class match selector.
Shorthand version $(':empty')
Description
The :empty
selector, selects all childless elements.
- By definition, self closing tags such as <br> and <img> are childless.
- Text nodes count as children.
- This selector is the inverse of
:parent
.
Syntax
Signature | Description |
---|---|
jQuery(':empty') | UI element states pseudo-class match |
Parameters
None.
Return
N/A.
:empty
ExamplesTop
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(){
$('#btn1').on('click', function() {
$("input:empty").css('backgroundColor', 'yellow');
});
});
Please fill in the form:
The following example will check for empty 'hr' elements and set an orange background when the button below is clicked.
$(function(){
$('#btn2').on('click', function() {
$("hr:empty").css('backgroundColor', 'orange');
});
});