EN
JavaScript - get node name
0 points
In this article, we would like to show you how to find the node name of the node using JavaScript.
Quick solution:
xxxxxxxxxx
1
node.nodeName;
In this example, we get all nodes of the container
and get their names using the nodeName
property.
xxxxxxxxxx
1
2
<html>
3
<body>
4
<div id="container">text-node<div></div><br><span></span></div>
5
<script>
6
7
var nodes = document.querySelector('#container').childNodes;
8
9
for (var node of nodes) {
10
console.log(node.nodeName);
11
}
12
13
</script>
14
</body>
15
</html>