views:

72

answers:

2

Say i have the following:

<a class="class1"><img src=".." /></a>

If I am currently in the click event of a.class1, how to I pull the 'src' value of the 'img'?

Update: for some reason neither of the suggestions below worked. My code looks like this:

 $("a.class1").click( function() {
     alert($(this).children('img').attr('src'));
 });

This pops up 'undefined' (for both suggestions). Why is this happening?

+2  A: 

Try:

$("img", this).attr("src")
Ates Goral
+2  A: 

Like this:

$(this).children('img').attr('src')
nickf