Attribute item() Method - Use attributes[index] to get attribute - Javascript DOM

Javascript examples for DOM:Attribute

Description

Attribute item() Method - Use attributes[index] to get attribute

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
.example {/*from w ww.  ja  v a 2 s  .com*/
    color: red;
    padding: 10px;
    width: 150px;
    font-size: 15px;
}
</style>
</head>
<body>

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

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

<script>
function myFunction() {
    var a = document.getElementsByTagName("BUTTON")[0];
    var x = a.attributes[1].name;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials