Jquery: Checking to see if div contains text, then action

后端 未结 7 1262
野趣味
野趣味 2020-11-28 06:47

I\'m trying to check in jQuery if a div contains some text, and then add a class if it does.

So I wrote something like this:

    if( $(\"#field >          


        
相关标签:
7条回答
  • 2020-11-28 07:19
    if( $("#field > div.field-item").text().indexOf('someText') >= 0)
    

    Some browsers will include whitespace, others won't. >= is appropriate here. Otherwise equality is double equals ==

    0 讨论(0)
提交回复
热议问题