EN
JavaScript - find tag name of HTML element
0 points
In this article, we would like to show you how to find the tag name of the HTML element using JavaScript.
Quick solution:
xxxxxxxxxx
1
element.tagName;
In this example, we get handles to all elements of the document.body
and display their tags using the tagName
property.
xxxxxxxxxx
1
2
<html>
3
<body>
4
<div>Div element's text...</div>
5
<br>
6
<img id="image" src="/static/bucket/1631898942509-VMYrnXyYZv--image.png" height="50px" />
7
<script>
8
9
var elements = document.body.children;
10
11
for (var element of elements) {
12
console.log(element.tagName);
13
}
14
15
</script>
16
</body>
17
</html>