Jquery 无法选择特定类的子元素
为什么这不起作用Jquery 无法选择特定类的子元素,jquery,Jquery,为什么这不起作用 <div class='folder lev1'>323</div> <div class='folder lev2'>525</div> <div class='file lev3'>727</div> <div class='file lev3'>929</div> <div class='folder lev1'>end</div> 控制台没有错误。在
<div class='folder lev1'>323</div>
<div class='folder lev2'>525</div>
<div class='file lev3'>727</div>
<div class='file lev3'>929</div>
<div class='folder lev1'>end</div>
控制台没有错误。在您的示例中,.lev1没有任何儿童。他有兄弟姐妹
$(".lev1").click(function(){
if ($(this).next().is(":visible")) {
$(this).nextUntil(".lev1").hide(); // works
}
else {
$(this).siblings(".lev2").show(); // works
}
});
或者,如果希望显示下一个.lev2:
$(".lev1").click(function(){
if ($(this).next().is(":visible")) {
$(this).nextUntil(".lev1").hide(); // works
}
else {
$(this).nextAll(".lev2").show(); // works
}
});
在您的示例中,.lev1没有任何儿童。他有兄弟姐妹
$(".lev1").click(function(){
if ($(this).next().is(":visible")) {
$(this).nextUntil(".lev1").hide(); // works
}
else {
$(this).siblings(".lev2").show(); // works
}
});
或者,如果希望显示下一个.lev2:
$(".lev1").click(function(){
if ($(this).next().is(":visible")) {
$(this).nextUntil(".lev1").hide(); // works
}
else {
$(this).nextAll(".lev2").show(); // works
}
});
多么愚蠢的错误啊。非常感谢。@bonaca,没问题。真是个愚蠢的错误。非常感谢。博纳卡,没问题。考虑我的更新答案。考虑我的更新答案。