tags:

views:

114

answers:

2
+2  A: 

The reason your code is not working is that jQuery(this) in your alert is actually an anchor, and not an image, and thus, it does not have any src attribute. Since your anchor contains an image, you'll be able to adjust your code to:

jQuery('#tab a').click(function() {
   alert(jQuery(this).find('img').attr('src'));
});
David Hedlund
Thank you so much! i have just forgotten the "find"...
codeworxx
+1  A: 

You could simply find the image within the anchor tag you have clicked (i.e. search within the anchor container.)

$('#tab a').click(function()
{
   alert($("img", $(this)).attr("src"));
});
gg
You can use `$("img", this)`, jQuery can get DOM element as context (second argument), not only jQuery object.
MBO