Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery find element with class and style display:block

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 ?
like image 911
spiderman Avatar asked Sep 30 '13 09:09

spiderman


People also ask

How do you check if an element has a specific class in jQuery?

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

How check element is displayed or not in jQuery?

Syntax: $(element).is(":visible"); Example 1: This example uses :visible selector to check an element is visible or not using jQuery.


2 Answers

You can use :visible to get element which are visible.

$(".highlight:visible").length
like image 64
Adil Avatar answered Sep 22 '22 12:09

Adil


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
       }
    });
like image 43
Somnath Kharat Avatar answered Sep 21 '22 12:09

Somnath Kharat