jQuery if “this” contains

前端 未结 4 689
予麋鹿
予麋鹿 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:01

    I don't think there is a .contains function in jQuery. There is a .contains function but that function is used to see if a DOM element is a descendant of another DOM element. See documentation for .contains. (Credits to @beezir)

    I think you are looking for :contains selector. See below for more details,

    $('#main-content-panel .entry:contains("Replace Me")').css('color', 'red');
    

    http://jsfiddle.net/zatHH/1/

提交回复
热议问题