JQuery select all rows containing certain text wit

2020-03-08 07:44发布

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>

3条回答
Viruses.
2楼-- · 2020-03-08 08:10

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

查看更多
乱世女痞
3楼-- · 2020-03-08 08:20

Try:

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

Demo here.

查看更多
神经病院院长
4楼-- · 2020-03-08 08:23

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

$("tr:has(td:contains('1'))").each(function () {
查看更多
登录 后发表回答