tags:

views:

62

answers:

4

Hi, i can get all childs with this code

$('#all').children().each(function() { .... });

But how can i get all visible childs with class "one" from id="all" ?

<div id="all">

    <div>asdd</div>
    <div class="one">content</div>
    <div class="one">bla</div>

    <div>
        ssss
        <div class="one" style="display:none">text</div>
    </div>

    <div class="one" style="display:none">blub</div>

</div>

Thanks in advance. Peter

+1  A: 

Would this work?

$('.one:visible', '#all')
Tahbaza
Yes, it would work
Ben
+1  A: 

You can use the :visible filter selector like this:

$('#all').find('.one:visible').each(function(){
  // your code....
});
Sarfraz
A: 

Try this, save as an .html file for an example

<html>
<head>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"&gt;&lt;/script&gt;
    <script>
        $(document).ready(function(){

            $('#all').children().each(function() { 
                if($(this).hasClass('one') && $(this).css('display') != 'none')
                {
                    alert($(this).html());
                }
            });
        });
    </script>
</head>
<body>
    <div id="all">

        <div>asdd</div>
        <div class="one">content</div>
        <div class="one">bla</div>

        <div>
            ssss
            <div class="one" style="display:none">text</div>
        </div>

        <div class="one" style="display:none">blub</div>

    </div>
</body>
</html>
Brandon Boone
A: 

You can use the following simple jQuery function

$('#all .one:visible');

This will get you all the visible elements with class one. (enclosed within the #all)

kapser