I am trying to retrieve the image source of an image that the user has clicked on.
This is what I have and it doesn’t seem to be working:
var imgSrc = getSrc(image)
function getSrc(image) {
$('img').each(function() {
$(this).click(function() {
$(this).attr('src')
}); //end click
}); //end each
} //end getSrc
You don’t need any loop. Above code will work just fine, I think.
Full code
Note
In your question you don’t use
imagearguments in code. I’m not sure why you’re using this. If you want to use getsrcof thatimageyou passed via arguments then you can try: