jQuery if “this” contains

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

    :contains is a selector. To check if a selector applies to given variable, you can use is:

    if($(this).is(':contains("Replace Me")')) 
    

    However Vega's solution is cleaner in this case.

提交回复
热议问题