您好我正在尝试将目标放在.current-cat-parent下的第一个<a>
元素,但是我的jquery代码正在影响下方的所有<a>
元素。我怎样才能瞄准第一个即时<a>
元素?谢谢!:影响所有孩子的第一个孩子
$(".current-cat-parent a:first-child").click(function(e){
e.preventDefault();
if($(this).hasClass('hide')){
$(this).next().slideDown(800);
$(this).removeClass('hide');
} else {
$(this).next().slideUp(800);
$(this).addClass('hide');
}
});
<li class="cat-item cat-item-1 current-cat-parent">
<a title="View all posts filed under Clothing" href="http://site.com/category/clothing">Clothing</a>
<ul class="children">
<li class="cat-item cat-item-3"><a title="View all posts filed under Jeans" href="http://site.com/category/clothing/jeans">Jeans</a></li>
<li class="cat-item cat-item-2 current-cat"><a title="View all posts filed under Suits" href="http://site.com/category/clothing/suits">Suits</a></li>
</ul>
</li>
锚是所有的第一个孩子在他们的上下文? - >'$(“。current-cat-parent a:first”)' – adeneo