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:
attribute.localName
Practical example
In this example, we use the localName property to get the local part of the qualified name of an attribute.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<body>
<div id="element-id" class="visible" custom-attribute="value">Example text...</div>
<script>
var myElement = document.querySelector('#element-id');
console.log(myElement.attributes[0].localName);
console.log(myElement.attributes[1].localName);
console.log(myElement.attributes[2].localName);
</script>
</body>
</html>