我如何获得元素后有类的所有行,当它到达没有类的行时应停止 [英] How can I get all the rows which has class after an element it should stop when it gets to a row where no class
本文介绍了我如何获得元素后有类的所有行,当它到达没有类的行时应停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想要实现的是在当前行之后获取所有rows
.
它应该获取其后的所有行,直到不再具有特定类为止.
示例:
What I'm trying to achieve is fetch all the rows
after the current row.
It should fetch all the rows after it until it stops having no particular class.
Example:
<tr class="clicked_el"></tr>
<tr class="getme"></tr>
<tr class="getme"></tr>
<tr class="getme"></tr>
<tr class="getme"></tr>
<tr></tr> //It should stop here
<tr class="getme></tr>
当我单击类别为clicked_el的tr
时.我想获得所有带有getme
类的'tr',直到没有getme
类的tr
.
When I click on the tr
with class clicked_el. I want to get all the 'tr' with getme
class until the tr
with no getme
class.
我尝试使用nextAll
进行操作,但不知道如何在nextUntil
I tried doing it with nextAll
didnt know how to use filter with nextUntil
推荐答案
您可以使用$(".clicked_el").nextUntil(":not(.getme)")
这将返回:
<tr class="clicked_el"></tr>
<tr class="getme"></tr> <- This will be returned;
<tr class="getme"></tr> <- This will be returned;
<tr class="getme"></tr> <- This will be returned;
<tr class="getme"></tr> <- This will be returned;
<tr></tr>
<tr class="getme></tr>
演示
console.log($(".clicked_el").nextUntil(":not(.getme)").length)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr class="clicked_el"></tr>
<tr class="getme"></tr>
<tr class="getme"></tr>
<tr class="getme"></tr>
<tr class="getme"></tr>
<tr></tr>
<tr class="getme"></tr>
</tbody>
</table>
这篇关于我如何获得元素后有类的所有行,当它到达没有类的行时应停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文