Reputation: 549
I can get all the children of an element with this code
$('#all').children().each(function() { .... });
But how can i get all visible children 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>
Upvotes: 13
Views: 23243
Reputation: 16472
Try this example
$(document).ready(function(){
$('#all').children().each(function() {
if($(this).hasClass('one') && $(this).css('display') != 'none')
{
alert($(this).html());
}
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<head>
</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>
Upvotes: 0
Reputation: 619
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)
Upvotes: 5