$('.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'
1.4m articles
1.4m replys
5 comments
57.0k users