image alt value javascript
by Ramya[ Edit ] 2009-10-02 11:24:57
image alt value javascript:
Get alt attribute value of an image using javascript.
<script language=javascript>
function tt()
var altvalue = document.getElementsByTagName('img')[0].getAttribute('alt');
alert(altvalue);
</script>
<img alt='Circle' src='../images/circle.gif' id='circle' onclick='tt()'>
</body>
To have specific image alt value then specify the element's position by img[0],img[1],.. like above.
Another way is to use for loop to get all image tags alt values.
<script language="javascript">
var images = document.getElementsByTagName('img');
for (i = 0; i < images.length; i++)
{
var altvalue = images[i].alt;
}
</script>