Reputation: 11
Is it possible to address all li elements, which have a specific content without giving them a unique id/class? like:
<ul class="list">
<li>test</li>
<li>test2</li>
<li>test</li>
</ul>
All li's with the content "test" should get a red color.
Thanks for your help!
Upvotes: 1
Views: 99
Reputation: 14944
this should do the trick
$('li:contains("test")').css('color', 'red');
Upvotes: 1
Reputation: 12021
$(function() {
$('.list li').each(function() {
if ($(this).html() == 'test') {
$(this).css('color', 'red');
}
});
})
Upvotes: 0
Reputation: 35803
Filter should work pretty well for you here:
$('li')
.filter(function() { return $(this).text() === "test" })
.css('color', 'red');
http://jsfiddle.net/infernalbadger/KQPbA/
Upvotes: 0
Reputation: 1039588
You could use the .filter()
method:
$('li').filter(function() {
return $(this).text() === 'test';
}).css('color', 'red');
And here's a live demo.
Upvotes: 5