JSFiddle - React, Tailwind, and code Playground
HTML
<div class='c1'></div>
<div></div>
<span></span>
<a href=""></a>
JavaScript
function CountNodes(context) {
var _this = this;
this.nodes = document.querySelectorAll(context);
this.tags = {};
this.classes = {};
Array.prototype.forEach.call(this.nodes, function(el) {
_this.tags[el.tagName] = (_this.tags[el.tagName] || 0) + 1;
if (el.className) {
var classList = el.className.trim().split(' ');
classList.forEach(function(el) {
_this.classes[el] = (_this.classes[el] || 0) + 1;
});
}
});
}
CountNodes.prototype.printTags = function() {
for (var key in this.tags) {
console.log('Элементов ' + key + ' -- ' + this.tags[key]);
}
return this;
}
CountNodes.prototype.printClasses = function() {
for (var key in this.classes) {
console.log('Элементов с классом ' + key + ' -- ' + this.classes[key]);
}
return this;
}
//
new CountNodes('body *')
.printTags()
.printClasses();