The name
property returns the name of the attribute.
name |
Yes | Yes | Yes | Yes | Yes |
attribute.name;
A String representing the name of the attribute.
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: