<div class="class1">Element 1</div>
<div class="class2">Element 2</div>
<div class="class1">Element 3</div>
<div class="class3">Element 4</div>
<div class="class2">Element 5</div>
<p id="result"></p>
// An array of class names you want to count
var classNamesToCount = ['class1', 'class2', 'class3'];
var classCounts = {}; // Object to store class counts
classNamesToCount.forEach(function(className) {
var elementsWithClass = document.getElementsByClassName(className);
classCounts[className] = elementsWithClass.length;
});
// Display the counts
var resultText = "Number of elements with different classes:\n";
for (var className in classCounts) {
resultText += "'" + className + "': " + classCounts[className] + "\n";
}
document.getElementById("result").textContent = resultText;