简体   繁体   中英

Modifying table cell content if row contains specific string

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM