我想在div.first
中隐藏()第二和第三个div和第二个div<div class="first">
<div class="another"></div>
<div class="second"></div>
<div class="second"></div> // Hide this
<div class="second"></div> // Hide this
<div class="second"></div>
</div>
<div class="first">
<div class="another"></div>
<div class="second"></div>
<div class="second"></div> // Hide this
<div class="second"></div> // Hide this
<div class="second"></div>
</div>
如何在头等舱中选择每个第2和第3个div 用jquery?
答案 0 :(得分:2)
尝试使用.each()
,.slice()
$(".first").each(function() { $(".second", this).slice(1,3).hide() })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
</script>
<div class="first">
<div class="another"></div>
<div class="second">first</div>
<div class="second">second</div> // Hide this
<div class="second">third</div> // Hide this
<div class="second">fourth</div>
</div>
<div class="first">
<div class="another"></div>
<div class="second">first</div>
<div class="second">second</div> // Hide this
<div class="second">third</div> // Hide this
<div class="second">fourth</div>
</div>
答案 1 :(得分:1)
答案 2 :(得分:0)
您可以nth-child
使用
$('.second:nth-child(3), .second:nth-child(4)', '.first').hide();
$('.second:nth-child(3), .second:nth-child(4)', '.first').hide();
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="first">
<div class="another">1</div>
<div class="second">2</div>
<div class="second">3</div> <!-- Hide this -->
<div class="second">4</div> <!-- Hide this -->
<div class="second">5</div>
</div>
<div class="first">
<div class="another">1</div>
<div class="second">2</div>
<div class="second">3</div> <!-- Hide this -->
<div class="second">4</div> <!-- Hide this -->
<div class="second">5</div>
</div>
&#13;