Get image or image url on select that image

Manu picture Manu · Oct 27, 2011 · Viewed 10.9k times · Source

How can i get the image or image url on select that image using javascript, any examples?

Thanks Manoj

Answer

James Allardice picture James Allardice · Oct 27, 2011

Your question is far from clear, but assuming an image with an id of myImage, and assuming that by "select" you mean "click", you can do this:

document.getElementById("myImage").onclick = function() {
    console.log(this.src);
}

Here's a working example. Clarify your question and I can clarify my answer.