If element contains certain text

前端 未结 3 1596
猫巷女王i
猫巷女王i 2020-12-06 10:23
$(\'.test\').css(\'background\',\'red\');

Some text

How can I .addClass(\'test\') if #exa

3条回答
  •  萌比男神i
    2020-12-06 11:10

    try the following code

    $('#example:contains("text")').addClass('test');
    

    Have a look here for examples and explanations of the :contains selector

提交回复
热议问题