jQuery if “this” contains

前端 未结 4 696
予麋鹿
予麋鹿 2021-01-31 18:19

I\'m trying to change any elements containing a particular text string to a red color. In my example I can get the child elements to become blue, but there\'s something about th

4条回答
  •  长情又很酷
    2021-01-31 19:02

    I think we should convert our text to lower case. It is better to check with lowercase and uppercase.

    $('#main-content-panel .entry').each(function() {
        var ourText = $(this).text().toLowerCase(); // convert text to Lowercase
        if(ourText.match('replace me')) {
            $(this).css('color', 'red'); 
        }      
    });
    

提交回复
热议问题