views:

208

answers:

5

I also need to find out all the elements inside a div, and check for their visibility. How to do it?

+6  A: 

You can select them using the :visible and :hidden pseudo-elements. For example, selects all the visible descendants of a <div>.

$("div :visible")...

Of you can do a test using is(). For example:

if ($("#someId").is(":visible")) { ...
cletus
A: 
$('#myElement').is(':visible');

Will return true or false

jeerose
A: 

Use the :hidden and :visible selectors.

$("div:visible").hide();

$("div:hidden").show();

Alex
+2  A: 

The first part of your question sounds like you want to find all the elements inside of a div. And then check for visibility.

To get all elements that are descendants of a div, use:

$('#myDiv *')

So to test each element, and act accordingly based on visibility:

$('#myDiv *').each(function() {
    if( $(this).is(':visible') ) {
        // code to run if visible
    } else {
        // code to run of not visible
    }
})
patrick dw
A: 

use the $(div :visible) selector to select all visible elements in the div. you may loook at http://api.jquery.com/visible-selector/ for more details.