Attribute length Property - Find out how many attributes an <img> element has - Javascript DOM

Javascript examples for DOM:Attribute

Description

Attribute length Property - Find out how many attributes an <img> element has

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img id="myImg" alt="Flower" src="http://java2s.com/resources/a.png" width="150" height="113">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w  ww  . j a v  a  2s  .c o  m*/
    var x = document.getElementById("myImg").attributes.length;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials