When using the 'this' keyword in jQuery, what is the syntax for adding basic filters.
For example:
$(this):contains('foo')
$(this):visible OR $(this:visible)
When using the 'this' keyword in jQuery, what is the syntax for adding basic filters.
For example:
$(this):contains('foo')
$(this):visible OR $(this:visible)
use this syntax: jQuery( expression, [context] )
$(":contains(foo)", this)
$(":visible", this)
$("any-selector", this)
That's what the filter() method is for:
$(this).filter(":contains(foo)");
$(this).filter(":visible")
According to the docs:
Removes all elements from the set of matched elements that do not match the specified expression(s).
For Searching for items within this:
$(':visible, any-selector', this)
$(this).find(':visible, any-selector')
if you want a true or false return:
if($(this).is(':visible, any-selector')){
alert('this is visible, or matches "any-selector");
}
else{
alert('this is hidden, or doesn't match "any-selector");
}