I am retrieving the number of "found" elements (these elements have the .highlight
class) with this simple jQuery snippet:
$(".highlight").length
But now my problem is that some elements are hidden, via style="display: none;"
Now, How can I get the number of elements highlighted AND displayed?
Something like:
$(hasClass 'highlight' AND has style 'display: block'). length ?
jQuery hasClass() Method The hasClass() method checks if any of the selected elements have a specified class name. If ANY of the selected elements has the specified class name, this method will return "true".
Syntax: $(element).is(":visible"); Example 1: This example uses :visible selector to check an element is visible or not using jQuery.
You can use :visible to get element which are visible.
$(".highlight:visible").length
U can also do by using css to see the element has css display="none"
or display="block"
$(".highlight").each(function(){
if($(this).css("display")=="block"){
//Your code here
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With