EN
JavaScript - getAttributeNode() method example
0 points
In this article, we would like to show you how to get attribute node using getAttributeNode()
method in JavaScript.
Quick solution:
xxxxxxxxxx
1
someElement.getAttributeNode(attributeName);
Where:
someElement
- reference to some element,attributeName
- name of the attribute insomeElement
.
The example shows how to get attribute node with getAttributeNode
method.
xxxxxxxxxx
1
2
<html>
3
<body>
4
<div id="my-div" class="my-class">This is my div.</div>
5
<script>
6
7
var myDiv = document.querySelector('#my-div'); // gets element by id
8
var attributeNode = myDiv.getAttributeNode('class'); // gets attribute node
9
10
console.log(attributeNode.value); // displays node value
11
12
</script>
13
</body>
14
</html>