我有以下内容:
<div id=box1>
<div id='1' class='product' style=""></div>
<div id='2' class='product' style="display: none;"></div>
<div id='3' class='product' style="display: none;"></div>
</div>
<div id=box2>
<div id='4' class='product' style=""></div>
<div id='5' class='product' style="display: none;"></div>
<div id='6' class='product' style="display: none;"></div>
</div>
<div id=box3>
<div id='7' class='product' style=""></div>
<div id='8' class='product' style="display: none;"></div>
<div id='9' class='product' style="display: none;"></div>
</div>
我想做的是专门处理特定框中的元素并忽略所有其他元素。
我知道我需要使用子元素,这就是我目前拥有的:
$( "some-click-event" ).click(function() {
var boxid = $(this).data("boxid"); //taken from the clicked element
//Now I want to work exclusively with the particular box
$("#" + boxid).children(function() {
//Now I need to recurse through each box element
$( ".product" ).each(function( index ) {
//Toggle display
});
});
});
所以我的问题是:如何定位特定的盒子 ID?
最佳答案
您可以使用find
方法:
$("#box" + boxid).find( '.product' ).each(function() {
//Toggle display
$( this ).toggle();
});
关于javascript - Jquery - 查找子ID的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27709026/