jquery,按类查找下一个元素 [英] jquery, find next element by class
本文介绍了jquery,按类查找下一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过类找到下一个元素。
How can i find the next element by class.
我尝试过 $(obj).next('。class');
,但这只会返回 $(obj)
parent中的类。
我需要将下一个元素放在整个代码的任何地方,按类名。
因为我的代码看起来像
i tried with $(obj).next('.class');
but this returns classes only in $(obj)
parent.
I need to take the next element anywhere throughout the code by class name.
Because my code looks like
<table>
<tr><td><div class="class">First</div></td></tr>
<tr><td><div class="class">Second</div></td></tr>
</table>
这是否可能?
推荐答案
在这种情况下,您需要前往< tr>
use .next()
,例如:
In this case you need to go up to the <tr>
then use .next()
, like this:
$(obj).closest('tr').next().find('.class');
或者如果两者之间可能存在 .class
里面,您可以使用
.nextAll()
,例如:
Or if there may be rows in-between without the .class
inside, you can use .nextAll()
, like this:
$(obj).closest('tr').nextAll(':has(.class):first').find('.class');
这篇关于jquery,按类查找下一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文