jQuery: find element by text

后端 未结 7 2251
攒了一身酷
攒了一身酷 2020-11-22 03:31

Can anyone tell me if it\'s possible to find an element based on its content rather than by an id or class?

I am attempting to find

7条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 04:02

    Rocket's answer doesn't work.

    hhhhhh
    This is a test
    Another Div

    I simply modified his DEMO here and you can see the root DOM is selected.

    $('div:contains("test"):last').css('background-color', 'red');
    

    add ":last" selector in the code to fix this.

提交回复
热议问题