views:

173

answers:

1

For example:

<table>
  <tr class="highlight" id="click">
    <td>Rusty</td>
  </tr>
  <tr class="indent">
    <td>Dean</td>
  </tr>
  <tr class="indent">
    <td>Hank</td>
  </tr>
  <tr class="highlight">
    <td>Myra</td>
  </tr>
</table>

Say when I click on the hr with the id click how would I find all instances of class indent until the next instance of class highlight?

+6  A: 
$('tr.highlight').click(function() {
    var $indents = $(this).nextAll('tr.indent');
});

EDIT

That's seems to select all .indents regardless of .highlights. Try this:

$('tr.highlight').click(function() {
    var row = $(this).next();
    var selection = false;
    while(row.hasClass('indent')) {
        if(!selection) {
            selection = row;
        } else {
            selection.add(row);
        }
        row = row.next();
    }
});
Tatu Ulmanen
The only problem with this is if there are more indent past the next highligt.
ChaosPandion
+1 you beat me to it.
ChaosPandion
This seems to work, thanks.
Hooray Im Helping