views:

49

answers:

3

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
});
+3  A: 

To select by class name, put a dot at the start:

$('.my_class a:contains("string")')
nickf
actually, I had a typo. I included a '.' for the class and it's still not working.
proee
+1  A: 

Try this, with a dot at the start of the class name:

$('.my_class a:contains('string').each(function(i){
//do some stuff
});
Justin Ethier
+1  A: 

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/

Matt
thanks for the catch. Looks Like I had some mis matching going on.
proee