Element attributes Property - Get the name of a <button> element's second (index 1) attribute: - Javascript DOM

Javascript examples for DOM:Element attributes

Description

Element attributes Property - Get the name of a <button> element's second (index 1) attribute:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {/*from   w  w w. j  av a2  s.  c  o m*/
    var x = document.getElementById("myBtn").attributes[1].name;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials