Change the color of a text in div using jquery contains

后端 未结 6 825
别那么骄傲
别那么骄傲 2021-01-13 07:47

Here the whole text inside the div get\'s red color. but I need only the \"bar\" word color to be changed



        
6条回答
  •  温柔的废话
    2021-01-13 08:22

    $("div:contains('bar')").each(function () {
        $(this).html($(this).html().replace("bar", "bar"));
    });
    

    this will work surely

    Please see Demo Here

提交回复
热议问题