EN
JavaScript - get attribute name
0 points
In this article, we would like to show you how to get an attribute's local name using JavaScript.
Quick solution:
xxxxxxxxxx
1
attribute.localName
In this example, we use the localName
property to get the local part of the qualified name of an attribute.
xxxxxxxxxx
1
2
<html>
3
<body>
4
<div id="element-id" class="visible" custom-attribute="value">Example text...</div>
5
<script>
6
7
var myElement = document.querySelector('#element-id');
8
9
console.log(myElement.attributes[0].localName);
10
console.log(myElement.attributes[1].localName);
11
console.log(myElement.attributes[2].localName);
12
13
</script>
14
</body>
15
</html>