Given HTML like:
<div clas开发者_开发知识库s="itemList">
<div class="streamBox version-2"> stuff </div>
<div class="streamBox version-2"> stuff </div>
<div class="streamBox version-3"> stuff </div>
<div class="streamBox version-2"> stuff </div>
<div class="streamBox version-3"> stuff </div>
<div class="streamBox version-1"> stuff </div>
</div>
How can I get jquery to loop through all the '.streamBox' inside of the '.itemList' div?
When looping through, given a version #, like 2, how to get it to show() version-2 but hide all the others?
Thanks
$('.itemList').children().hide().filter('.version-2').show();
Also, use the UL element:
<ul class="itemList">
<li class="version-2"> stuff </li>
<li class="version-2"> stuff </li>
<li class="version-3"> stuff </li>
<li class="version-2"> stuff </li>
<li class="version-3"> stuff </li>
<li class="version-1"> stuff </li>
</ul>
$('.itemList').children('.steamBox').each(function(index) {
// Now you can use $(this) to manipulate a list item
if (index != 2) // index starts at 0
$(this).hide();
});
try something like:
function showVersion(ver) {
$('.streamBox').hide();
$('.version-' + ver).show();
}
精彩评论