Element attributes Property - Find out how many attributes an <img> element have: - Javascript DOM

Javascript examples for DOM:Element attributes

Description

Element attributes Property - Find out how many attributes an <img> element have:

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 w  w  .ja v a2s  . com*/
    var x = document.getElementById("myImg").attributes.length;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials