jQuery:单击一个元素时显示下一个Class-Element

时间:2013-11-13 10:34:54

标签: jquery html css next

我已经发现了这种威胁:How to toggle only the *next* .class or div (not the rest)

但是,如果我要切换的类不是click元素的子元素,我必须做的事情,例如:

<span onclick="$(this).next('.showme').slideToggle();">Klick to show first Showme-Class</span>
<div class="showme">You've clicked the first span-element</div>

<span onclick="$(this).next('.showme').slideToggle();">Klick to show second Showme-Class</span>
<div class="showme">You've clicked the second span-element</div>

<span onclick="$(this).next('.showme').slideToggle();">Klick to show third Showme-Class</span>
<div class="showme">You've clicked the third span-element</div>

更具体: 在这个例子中......

<div class="myclickclass">
<span onclick="this().next('.showme').slideToggle(100);">Click me</span>
<div class="showme">You've clicked</div>
</div>

类“showme”是类“myclickclass”的一部分(内部).... jQuery适合我。

<div class="myclickclass">
<span onclick="this().next('.showme').slideToggle(100);">Click me</span>
</div>
<div class="showme">You've clicked</div>

在这个例子中,“showme”类不是我的类“myclickclass”的一部分。 jQuery对我不起作用。

1 个答案:

答案 0 :(得分:2)

$(this).parent().next('.showme')

如果不是INSIDE。

相关问题