我正在创建一个常见问题页面,通过单击问题来切换答案。问题是h3,答案是几个p-elements。如下所示:
<h3>The First Question</h3>
<p>Answer Paragraph</p>
<p>Answer Paragraph</p>
<p>Answer Paragraph</p>
<h3>The Second Question</h3>
<p>Answer Paragraph</p>
<p>Answer Paragraph</p>如何切换属于某个问题的所有p-elements?我的JS在页面上切换所有p-elements:
$(document).ready(function(){
$("p").hide();
$("h3").click(function(){
$(this).nextAll("p").toggle();
});
});我不能使用div或类)。
发布于 2015-01-09 18:31:22
我推荐jQuery nextUntil();
$(document).ready(function(){
$("p").hide();
$("h3").click(function(){
$("h3").nextUntil("h3").toggle();
});
});https://stackoverflow.com/questions/1079938
复制相似问题