Attribute name Property - Javascript DOM

Javascript examples for DOM:Attribute

Description

The name property returns the name of the attribute.

This property is read-only.

Return Value

A String, representing the name of the attribute

The following code shows how to Get the name of an attribute:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

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

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

<script>
function myFunction() {//from   w  w  w  . java2  s  . com
    var btn = document.getElementsByTagName("BUTTON")[0];
    var x = btn.attributes[0].name;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials