|
|
image alt value javascript - Javascript
|
Views : 1482
|
|
Tagged in : Javascript
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
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> |
|
By Ramya, On - 2009-10-02 |
|
|
|