Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get list of Css class use in the HTML file?

Tags:

html

css

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?

like image 817
KuldipMCA Avatar asked Sep 24 '11 10:09

KuldipMCA


2 Answers

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());
like image 51
Ilia Choly Avatar answered Nov 17 '22 00:11

Ilia Choly


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.

like image 8
MisterGreen Avatar answered Nov 17 '22 01:11

MisterGreen