简体   繁体   中英

Traversing a table with jquery

I have some table rows:

<tr class='top'><td></td><td></td></tr>
<tr class='data'><td></td><td></td></tr>
<tr class='data'><td></td><td></td></tr>
<tr class='data'><td></td><td></td></tr>
<tr class='total'><td></td><td></td></tr>
<tr class='top'><td></td><td></td></tr>
<tr class='data'><td></td><td></td></tr>
<tr class='data'><td></td><td></td></tr>
<tr class='data'><td></td><td></td></tr>
<tr class='total'><td></td><td></td></tr>
...
...
...
<tr class='top'><td></td><td></td></tr>
<tr class='data'><td></td><td></td></tr>
<tr class='data'><td></td><td></td></tr>
<tr class='data'><td></td><td></td></tr>
<tr class='total'><td></td><td></td></tr>

I have selected a row of class data. Now I would like to find the row of class top that is in the same section and above my selected row.

Is there a jquery command that will do that for me?

Thanks!

You can use a mix of prevAll() and first() like

var $tr == //tr with class data
var $trop = $tr.prevAll('.top').first();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM