我想隐藏所有 class="csc-content",其中前一个兄弟是 h4 class="faq"。
更新错误:我认为这是错误的......之前的兄弟姐妹不是 h4。但我希望你明白如果“问题”具有“常见问题”/更新类,所有“答案”都应该被隐藏
这是html:
<div id="centerCol-1">
<div id="c65" class="csc-default normal">
<div class="csc-header csc-header-n1"><h4 class="faq">FAQ question1</h4></div>
<div class="csc-content active"><p class="bodytext">Answer1</p></div>
</div>
<div id="c67" class="csc-default normal">
<div class="csc-header csc-header-n2"><h4 class="faq">FAQ question2</h4></div>
<div class="csc-content active"><p class="bodytext">Answer2</p></div>
</div>
<div id="c68" class="csc-default normal">
<div class="csc-header csc-header-n3"><h4>not FAQ</h4></div>
<div class="csc-content active"><p class="bodytext">Not an answer, just normal content</p></div>
</div>
</div>
jQuery 应该是这样的:
// find all outer divs with class csc-default in the div centerCol-1
// test if they contain a header div with an h4 class faq
// go to next element and hide it. Error... this should be parents next element?
$("#centerCol-1 .csc-default").find("h4").is(".faq").next(".csc-content").hide();
BR。安德斯