Reputation: 801
I want to select all a elements that have text=mytext. I looking for something like that:
$('.scroll').find("a[text=" + "mytext" + "]").css('background-color', 'green');
Why this is not working?
edit:
<a href='http://stackoverflow.com'>stackoverflow</a>
text=stackoverflow
Upvotes: 0
Views: 135
Reputation: 57095
Use :contains()
$('.scroll').find("a:contains('mytext')").css('background-color', 'green');
Upvotes: 2
Reputation: 388316
in that case
$('.scroll a').filter(function(){
return $.trim($(this).text()) == 'mytext'
}).css('background-color', 'green');
:contains()
does not suit your case because it does not test for equality
Upvotes: 3
Reputation: 1428
You want to use :contains()
:
$('.scroll').find("a:contains('mytext')").css('background-color', 'green');
Upvotes: 1