Click here to Skip to main content
15,905,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a class name "test". i have load lots of div there. i want to use jquery to loop through the div and get the list of the div which are visible.

Does any one know how to accomplish this?
Posted

C#
<script>
     $(document).ready(function () {        
         $('.test').each(function () {
             if ($(this).is(':visible')) {
                //your code for visible Div with class='test'
             }
         });
     });
 </script>

Regards..
 
Share this answer
 
Comments
Nirav Prabtani 9-Jun-14 3:06am    
my 5+
thedinesh01 9-Jun-14 3:30am    
its not working for me.. i want all the div where are visible but not getting them.. :(
Thanks7872 9-Jun-14 3:34am    
I have tested and its working. Try to place this code at appropriate place. Its very important while you are working with Jquery.
$( "div" ).find(".test").each(function( i ) {
This will search for all the div having class "test"

});
 
Share this answer
 
Comments
Thanks7872 9-Jun-14 3:04am    
What about the visibility OP has asked for? Please see my solution above.

Solution


Loop through the Divs using jQuery each()[^].
Check if the div is visible or not using :visible Selector[^].
JavaScript
$(document).ready(function () {
    var divShowing = new Array();
    var divNotShowing = new Array();

    $('.test').each(function () {
        if ($(this).is(':visible')) {
            divShowing.push($(this));
        } else {
            divNotShowing.push($(this));
        }
    });

    alert("Number of Divs Visible: " + divShowing.length + "\n\n" + "Number of Divs Not Visible: " + divNotShowing.length);
});

Demo


[Demo] Find list of divs, which are visible[^]
 
Share this answer
 
Comments
thedinesh01 9-Jun-14 3:33am    
thank you so much i think i can do it now :)..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900