How to select this specific td element and its text with Jquery

前端 未结 6 472
温柔的废话
温柔的废话 2020-12-19 18:39

I want to change the \"Yes! Pick me\" into \"Picked\" with Jquery in the following HTML structure, I used $(\'#myDiv>table>tr>td>table>tr\').eq(1).text(

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-19 19:38

    You can use the :contains(text) selector

    $('#myDiv td table td:contains(Yes! Pick me!)').text('Picked');
    

    Be careful with nested tables however because if you were to use just

    $('#myDiv td:contains(Yes! Pick me!)').text('Picked');
    

    You would get both the cell your after plus the cell it is nested within.

提交回复
热议问题