JSFiddle - React, Tailwind, and code Playground
by pertrai1
HTML
<div id="main">
<h1>This is the header</h1>
<h2>This is the second header</h2>
<p>This is the paragraph</p>
</div>
JavaScript
function countTags(n) {
var numtags = 0;
if (n.nodeType == 1)
numtags++;
var children = n.childNodes;
for (var i=0; i < children.length; i++) {
numtags += countTags(children[i]);
}
return numtags;
}
alert ('This document has ' + countTags(document) + ' tags');