$('.test').css('background','red'); <div id="example">Some text</div>
How can I .addClass('test') if #example contains the word "text"?
.addClass('test')
#example
just use :contains pseudoclass
:contains
$('#example:contains("text")').addClass('test');
this will add the class to #example if it contains 'text'
2.1m questions
2.1m answers
60 comments
56.9k users