JSFiddle - React, Tailwind, and code Playground
by Paco86
HTML
<div class="out">
<div class="inner"></div>
</div>
CSS
.out {
width: 400px;
height: 400px;
background-color: #cccccc;
position: relative;
}
.inner {
width: 200px;
height: 200px;
background-color: red;
position: relative;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
JavaScript
function find(node, map) {
if (node.nodeType === 1) {
map.set(node.nodeName, (map.get(node.nodeName) || 0) + 1);
}
var childNodes = node.childNodes;
for (var i = 0; i < childNodes.length ; i++) {
find(childNodes[i], map)
}
}
function getTagsCount() {
var map = new Map();
find(document, map);
return map;
}
console.log(getTagsCount())