Briefkasten Briefkasten - 1 month ago 7
HTML Question

Select tr and its "tr childs" - find jquery selector

My table looks like the following:

<table class="highlight">
<tbody>
<tr class="sortable"><td>first row</td></tr>
<tr class="sortable nondraggable sub"><td>collasped row with further informations (belongs to row one)</td></tr>
<tr class="sortable nondraggable sub"><td>collasped row with further informations (belongs to row one)</td></tr>
<tr class="sortable nondraggable sub"><td>collasped row with further informations (belongs to row one)</td></tr>
<tr class="sortable"><td>second row</td></tr>
<tr class="sortable"><td>third row</td></tr>
<tr class="sortable nondraggable sub"><td>collasped row with further informations (belongs to third row)</td></tr>
<tr class="sortable"><td>fourth row</td></tr>
<tr class="sortable"><td>fifth row</td></tr>
<tr class="sortable nondraggable sub"><td>collasped row with further informations (belongs to fifth row)</td></tr>
<tr class="sortable nondraggable sub"><td>collasped row with further informations (belongs to fifth row)</td></tr>
</tbody>




I want to select each row with its "collapsed" childs.

For clarification: https://jsfiddle.net/4k1a6xp6/4/

I think it can be solved by using the child
">"
selector of jquery.
So we can use
jQuery("table.highlight").find("tr.sortable > ??? ")
.

The ??? should select the child trs with "
sortable nondraggable sub
" until the next parent row is reached.

How can I accomplish this?

T J T J
Answer

Select the parent row (with a specific selector as shown below, or while iterating over each of them, as per your requirement) then use nextUntil with :not selector. For example:

$('tr.sortable').first().nextUntil('tr.sortable:not(.nondraggable.sub)')