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

后端 未结 7 1324
野趣味
野趣味 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 06:59

    Ayman is right but, you can use it like that as well :

    if( $("#field > div.field-item").text().indexOf('someText') >= 0) {
            $("#somediv").addClass("thisClass");
        }
    

提交回复
热议问题