hi, im having an img tag in my html when click on image javascript function alerts the image src path..
<image src="angel_wall.jpg" onclick="do_some();return false;" />
hi, im having an img tag in my html when click on image javascript function alerts the image src path..
<image src="angel_wall.jpg" onclick="do_some();return false;" />
If you want to alert the image’s src
path when clicking on it, try this:
<img src="angel_wall.jpg" onclick="do_some(this)">
And the do_some
function:
function do_some(elem) {
alert(elem.src);
}
It may look like you mean this:
<img src="/path/angel_wall.jpg" onclick="alert(this.src);" />
function do_some(img) {
alert(img.src);
}
<img src="angel_wall.jpg" onclick="do_some(this);" />
Note that 'src' will return the full URL in most browsers. To get only the filename, you'll have to do something like this:
var src = img.src;
if(src.indexOf('/') > 0)
src = src.substring(src.lastIndexOf('/')+1);
alert(src);
<img id="test" src="angel_wall.gif" onClick="alert(document.getElementById('test').src)" />