
Enter a search term above to see results...
Enter a search term above to see results...
Logical operator methods in Query allow you to perform checks and filtering operations on sets of elements.
Checks the current matched set of elements against a selector, element, or Query object and returns true if at least one of these elements matches the given arguments.
$('selector').is(selector)
Name | Type | Description |
---|---|---|
selector | String or Function | A string containing a selector expression to match elements against or a function to test each element |
boolean
- true
if at least one element matches, false
otherwise.
if ($('#myElement').is('.active')) { console.log('The element is active');}
Checks if there are any elements in the current Query object.
$('selector').exists()
boolean
- true
if the Query object contains at least one element, false
otherwise.
if ($('.my-element').exists()) { console.log('The element exists in the DOM');} else { console.log('The element does not exist in the DOM');}
Quick Check
exists()
is a convenient way to check for the presence of elements without needing to compare the length property.
Remove elements from the set of matched elements.
$('selector').not(selector)
Name | Type | Description |
---|---|---|
selector | String or Function | A string containing a selector expression to match elements against or a function to test each element |
A new Query object with elements that do not match the selector.
$('div').not('.ignore').addClass('highlight');
Inverse Selection
not()
is particularly useful for excluding specific elements from a larger set based on various criteria.