質問をクリックすると回答が切り替わる FAQ ページを作成しています。問題はh3
、答えはいくつかのp
要素です。このような:
<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
特定の質問に属するすべての要素を切り替えるにはどうすればよいですか? 私のJSp
は、ページ上の次のすべての要素を切り替えます:
$(document).ready(function(){
$("p").hide();
$("h3").click(function(){
$(this).nextAll("p").toggle();
});
});
div
やクラスは使用できません)。