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

后端 未结 7 1322
野趣味
野趣味 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:54

    Why not simply

    var item = $('.field-item');
    for (var i = 0; i <= item.length; i++) {
           if ($(item[i]).text() == 'someText') {
                 $(item[i]).addClass('thisClass');
                 //do some other stuff here
              }
         }
    

提交回复
热议问题