JQuery: how to map all elements to a specific class that follow an element?

Here is my HTML code:

<tr>
  <td>data 1</td>
</tr>
<tr class="test">
  <td>test data 1</td>
</tr>
<tr class="test">
  <td>test data 2</td>
</tr>
<tr>
  <td>data 2</td>
</tr>

The first is <tr>assigned "var myVar". How to remove all subsequent elements <tr>containing a class "test"until it reaches the next element <tr>? Wrapping them in SPAN / DIV or performing global matching on is ".test"NOT an option.

$(myVar)......? :)

Thank.

+3
source share
1 answer
$(myVar).nextUntil("tr:not(.test)").remove()
+7
source

Source: https://habr.com/ru/post/1780921/


All Articles