问题
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