Reputation: 211
I'm using jQuery :contains selector to filter through some link tags. The following code works great.
$('a:contains("string")').each(function(i){
//do some stuff
});
I'd like only run this function if the anchor tags are inside a specific class, I've tried the following but it does not appear to work:
$('.my_class a:contains("string")').each(function(i){
//do some stuff
});
Upvotes: 2
Views: 3125
Reputation: 11
<div class="GridCell">Click to review.</div>
if you need to get the above using jQuery, use
$('div.GridCell:contains(Click to review.)')
Upvotes: 1
Reputation: 75317
Neither of those will work. You've got brackets and mis matching quotes all over the shop.
$('a:contains(string)').each(function(i){
//do some stuff
});
and then
$('.my_class a:contains(string)').each(function(i){
//do some stuff
});
Which now works: http://www.jsfiddle.net/muzQQ/
Upvotes: 2
Reputation: 134157
Try this, with a dot at the start of the class name:
$('.my_class a:contains('string').each(function(i){
//do some stuff
});
Upvotes: 1
Reputation: 546045
To select by class name, put a dot at the start:
$('.my_class a:contains("string")')
Upvotes: 3