Change the color of a text in div using jquery contains

后端 未结 6 726
别那么骄傲
别那么骄傲 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:11

    You can use this way :

           $(document).ready(function(){
                   //  $("#foo:contains('bar')").css('color','red');
                   var text = 'bar' ;
                   var  context = $("#foo").html();
                   $("#foo").html(context.replace(text,''+text+''));
            });
    

提交回复
热议问题