jquery按标题切换内容
对于以下HTML:jquery按标题切换内容,jquery,toggle,Jquery,Toggle,对于以下HTML: <h1 id="t1">First Title</h1> <p class="contents" id="c1">First Content</p> <h1 id="t2">Second Title</h1> <p class="contents" id="c2">Second Content</p> <h1 id="t3">Third Title<
<h1 id="t1">First Title</h1>
<p class="contents" id="c1">First Content</p>
<h1 id="t2">Second Title</h1>
<p class="contents" id="c2">Second Content</p>
<h1 id="t3">Third Title</h1>
<p class="contents" id="c3">Third Content</p>
<!-- etc... -->
第一个标题
第一个内容
第二名
第二个内容
第三名
第三个内容
我想使用jquery来slideToggle
每个特定标题的内容。Ie:单击id=“t2”,我希望“c2”切换
感谢您的建议或代码
$('h1').click(function(){
$(this).next().slideToggle();
});
将类用于h1,因为它更适合您的需求 然后试试这个:
$('h1.h1class')。单击(函数(){
$(this).next('p.contents').slideToggle(500);
});代码>可能存在的重复项