Is this what you are looking for?
$(function () {
$('ul').find('li').filter(function () {
return this.innerHTML == 'two';
}).css('color','red')
})
Or to match it anywhere in the element (rather than only "two" being within it):
$(function () {
$('ul').find('li').filter(function () {
return /two/.test(this.innerHTML);
}).css('color','red')
})
Also, if it matters... chaining methods (.find().filter()
) seems to be faster than using contains
:
Performance test created for this specifically
Another related test
And your id's should be unique - but I'm assuming that it is just copy/pasting for sample code and that you don't actually have duplicate id's in your actual code.