I need list of classes used in an html file. Is there any tool where i can get list of classes in the HTML file?
This should work and it doesn't need jquery:
const used = new Set();
const elements = document.getElementsByTagName('*');
for (let { className = '' } of elements) {
for (let name of className.split(' ')) {
if (name) {
used.add(name);
}
}
}
console.log(used.values());
If you've got jQuery on the page, run this code:
var classArray = [];
$('*').each(function(){if(this.className!=""){classArray.push(this.className)}})
The variable classArray will contain all the classes specified on that HTML page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With