JQuery - 下一个元素和具有相同类的元素
我想要实现的是,当您单击一个跨度时,它会找到下一个 ul,然后将 hide/show/slideToggle 应用于与该 ul 具有相同类的其他 ul。
我的 html 看起来像这样:
<div class="wrapper">
<span class="featureTitle">Trigger</span>
<ul class="features1">
<li></li>
</ul>
</div>
<div class="wrapper">
<span class="featureTitle">Trigger</span>
<ul class="features2">
<li></li>
</ul>
</div>
<div class="wrapper">
<span class="featureTitle">Trigger</span>
<ul class="features1">
<li></li>
</ul>
</div>
等等...
我知道这些 JQuery 代码行不起作用,但它可能会让您了解我在做什么:)
jQuery('.featureTitle').click(function(){
var ulClass= jQuery(this).next('ul').attr('class');
jQuery(document).find(ulClass).slideToggle();
});
任何帮助将不胜感激!
What I want to achieve is that when you click on a span, it finds the next ul, and then apply a hide/show/slideToggle to other ul´s with the same class as that one.
My html looks something like this:
<div class="wrapper">
<span class="featureTitle">Trigger</span>
<ul class="features1">
<li></li>
</ul>
</div>
<div class="wrapper">
<span class="featureTitle">Trigger</span>
<ul class="features2">
<li></li>
</ul>
</div>
<div class="wrapper">
<span class="featureTitle">Trigger</span>
<ul class="features1">
<li></li>
</ul>
</div>
and so on...
I know these lines of JQuery code doesn't work, but it might give you an idea of what I'm on about :)
jQuery('.featureTitle').click(function(){
var ulClass= jQuery(this).next('ul').attr('class');
jQuery(document).find(ulClass).slideToggle();
});
Any help would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那应该可以解决问题。您可以通过添加“.”来创建基于该类的选择器。在类名之前
That should do the trick. you can just create a selector based on that class by adding "." before the class name