nth-childまたはcountに基づくセレクタに基づいていくつかの非表示項目を作成しようとしています。 最初の行の最初の項目をクリックすると、2番目の行の最初の項目が表示され、その行の他の項目は非表示になります。簡略化されたコードをお手伝いください。nth-childベースのサブカテゴリを複数の行に表示しない
$(document).ready(function(){
$(".subrow1 .item-a a:nth-child(1)").click(function(){
$(".subrow2 .idgroupsub:nth-child(1)").show();
$(".subrow2 .idgroupsub:nth-child(2)").hide();
$(".subrow2 .idgroupsub:nth-child(3)").hide();
$(".subrow2 .idgroupsub:nth-child(4)").hide();
$(".subrow2 .idgroupsub:nth-child(5)").hide();
$(".subrow2 .idgroupsub:nth-child(6)").hide();
});
$(".subrow1 .item-a a:nth-child(2)").click(function(){
$(".subrow2 .idgroupsub:nth-child(2)").show();
$(".subrow2 .idgroupsub:nth-child(1)").hide();
$(".subrow2 .idgroupsub:nth-child(3)").hide();
$(".subrow2 .idgroupsub:nth-child(4)").hide();
$(".subrow2 .idgroupsub:nth-child(5)").hide();
$(".subrow2 .idgroupsub:nth-child(6)").hide();
});
$(".subrow1 .item-a a:nth-child(3)").click(function(){
$(".subrow2 .idgroupsub:nth-child(3)").show();
$(".subrow2 .idgroupsub:nth-child(1)").hide();
$(".subrow2 .idgroupsub:nth-child(2)").hide();
$(".subrow2 .idgroupsub:nth-child(4)").hide();
$(".subrow2 .idgroupsub:nth-child(5)").hide();
$(".subrow2 .idgroupsub:nth-child(6)").hide();
});
});
http://jsfiddle.net/Lv5cn8xy/244/
https://api.jquery.com/ index /、https://api.jquery.com/eq/ – CBroe