JQuery select all rows containing certain text within a td in the row

偶尔善良 提交于 2019-12-22 01:26:06

问题


I have a table for which I am attempting to select all rows which have a td containing the text 'Test' and then hide the td with class 'ms-vb-icon' on all the matched rows

I intitally had the code below but this only hide the class on the last matched row

 $("td:contains('test'):last").parent().children(".ms-vb-icon").css("visibility","hidden");

So I tried this but its not working...

 $("tr:has(td:contains('test')").each(function(){
  (this).children(".ms-vb-icon").css("visibility","hidden");
  });

Simplified html look like this:

<table>
<tbody>
<tr>
<td class=ms-vb-icon></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td>test</td>
</tr>
</tbody>
<table>

回答1:


Try:

$("tr td:contains('test')").each(function(){
  $(this).siblings('td.ms-vb-icon').css("visibility","hidden");
});

Demo here.




回答2:


I guess you are missing ')' .It worked for me:

$("tr:has(td:contains('1'))").each(function () {



回答3:


Try with

$("tr:has(td:contains('test')").each(function(){
    $(this).parent().children(".ms-vb-icon").css("visibility","hidden");
});

The class .ms-vb-icon is a child of the tr while the $(this) function refer to the td



来源:https://stackoverflow.com/questions/4341620/jquery-select-all-rows-containing-certain-text-within-a-td-in-the-row

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!