需要 jquery 选择器从元素中选择下一个表
我需要一个选择器,它基本上从我单击的元素开始,并查找页面上具有特定类的下一个项目。请参阅下面的示例:
<table>
<tr>
<td>Blah blah blah</td>
<td><p class="click">Fire jquery</p></td>
</tr>
</table>
<table class="hidden">
<tr>
<td>blah blah blah</td>
<td>blah blah blah</td>
</tr>
</table>
$(document).ready(function() {
$('.hidden').hide()
$('.click').click(function() {
$(this).next('.hidden').fadeIn()
})
})
所以基本上我想在页面加载时隐藏隐藏类的所有内容。然后,当单击具有单击类的内容时,它应该向下扫描页面以查找具有隐藏类的下一个元素并将其淡入。我只会执行 ('.hidden').fadeIn() 但 iv 得到了多个隐藏的项目,所以它会淡入所有项目,我只想淡入下一个项目。
希望您理解这一切,我将非常感谢任何可以提供帮助的人,
谢谢
I need a selector that basically starts at the element that I have clicked and finds the next item with a certain class on the page. See my example below:
<table>
<tr>
<td>Blah blah blah</td>
<td><p class="click">Fire jquery</p></td>
</tr>
</table>
<table class="hidden">
<tr>
<td>blah blah blah</td>
<td>blah blah blah</td>
</tr>
</table>
$(document).ready(function() {
$('.hidden').hide()
$('.click').click(function() {
$(this).next('.hidden').fadeIn()
})
})
So basically i want to hide everything with the class of hidden when the page loads. Then when something with a class of click is clicked it should scan down the page for the next element with a class of hidden and fade it in. I would just do ('.hidden').fadeIn() but iv got more than one hidden item so it fades all of them in and I only want the next one to be faded in.
Hope you understand all this, I will be very grateful for anyone that can help
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
next('.hidden')
失败,因为它搜索直接同级 - 即,在与click
元素相同的上.
尝试查找
,并查找其同级:
或者
如果您想在
click
与其hidden
之间创建语义连接,考虑将它们都包装在div
中,例如:next('.hidden')
fails because it searches for immediate siblings - that is, on the same<td>
as theclick
element.Try finding the
<table>
, and look for its sibling:or
If you want to create a semantic connection between a
click
and itshidden
, consider wrapping them both in adiv
, for example: