Javascript 使用jQuery,如何查找出现在另一个类之间的类的所有实例

Javascript 使用jQuery,如何查找出现在另一个类之间的类的所有实例,javascript,jquery,jquery-selectors,traversal,Javascript,Jquery,Jquery Selectors,Traversal,例如: <table> <tr class="highlight" id="click"> <td>Rusty</td> </tr> <tr class="indent"> <td>Dean</td> </tr> <tr class="indent"> <td>Hank</td> </tr>

例如:

<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>
比如,当我用id单击hr时,单击如何查找类缩进的所有实例,直到下一个类实例高亮显示

编辑

这似乎是选择全部。缩进不考虑。高光。试试这个:

$('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();
    }
});
编辑

这似乎是选择全部。缩进不考虑。高光。试试这个:

$('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();
    }
});

这将仅将单击应用于单击时的高光,并仅返回单击与它遇到的下一个高光之间的缩进

它使用jQuery~next-sides选择器为您做更多的工作


这将仅将单击应用于单击时的高光,并仅返回单击与它遇到的下一个高光之间的缩进

它使用jQuery~next-sides选择器为您做更多的工作


唯一的问题是超过下一个高点的缩进量是否更多。唯一的问题是超过下一个高点的缩进量是否更多。
$("#click").bind('click', function() {
    var good = true;
    $("#click ~ tr").each(function(e) {
        if (this.className == "highlight") {
            good = false;
        }
        if (good && this.className == "indent") {
            this.style.background="red";
        }
    });
});