Javascript Reference - HTML DOM name Property








The name property returns the name of the attribute.

Browser Support

name Yes Yes Yes Yes Yes

Syntax

attribute.name;

Return Value

A String representing the name of the attribute.

Example

The following code shows how to get the name of an attribute.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--   w  ww .java2s  .  c o m-->
<p id="demo"></p>

<script>
function myFunction() {
    var btn = document.getElementsByTagName("button")[0];
    var x = document.getElementById("demo");
    x.innerHTML=btn.attributes[0].name;
}
</script>
</body>
</html>

The code above is rendered as follows: