JQuery – 找到第一个兄弟匹配选择器

如何获得列表中与选择器匹配的第一个(下一个)元素?

例:

<table>
  <tr class="test"><td>not this one</td></tr>
  <tr><td><a title="test">click</a></td></tr>
  <tr><td>not this one</td></tr>
  <tr class="test"><td>this one</td></tr>
  <tr class="test"><td>ignore this as well</td></tr>
</table>

$("a").on('click',function(eve){
  $(this).parents("tr").???(".test").toggle();
});

编辑

我需要以下一行.兄弟姐妹也得到了其他人(比如第一排)

解决方法

使用 .nextAll()获取元素的后续兄弟和 :first以获得第一个匹配的元素.

试试这个:

$("a").on('click',function(eve){
  $(this).parents("tr").nextAll(".test:first").toggle();
});

DEMO

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...