Hi I am trying to modify content in the 3rd cell of a table using jQuery if that table row contains specific string. My code is below. It doesn’t seem to work.
$(‘tr:contains(test1)’).find(‘td:nth-child(2)’).html(‘test2’);
Hi I am trying to modify content in the 3rd cell of a table using jQuery if that table row contains specific string. My code is below. It doesn’t seem to work.
$(‘tr:contains(test1)’).find(‘td:nth-child(2)’).html(‘test2’);
Alternative way to achieve above is using eq(2)
it will find element which is at 2
index starting from 0
.
Demo Code:
$("tr:contains(test1)").find("td:eq(2)").html("test2");
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td>1</td>
<td>test1 </td>
<td>something </td>
</tr>
<tr>
<td>2</td>
<td>test1 </td>
<td> something</td>
</tr>
<tr>
<td>3</td>
<td>test4 </td>
<td> something</td>
</tr>
</table>