Skip to content

Instantly share code, notes, and snippets.

@beatrizsmerino
Created July 29, 2020 11:15
Show Gist options
  • Save beatrizsmerino/92dcbd62ede69e84fe2a48be71e1db1a to your computer and use it in GitHub Desktop.
Save beatrizsmerino/92dcbd62ede69e84fe2a48be71e1db1a to your computer and use it in GitHub Desktop.
Get list of Css class use in the HTML file
function getListClassCss() {
let list = [];
let selectorsAll = document.querySelectorAll("[class]");
selectorsAll.forEach((event) => {
let selectorClassAll = event.getAttribute("class").split(" ");
selectorClassAll.forEach(
(classCss) => {
if (classCss.length > 0 && list.indexOf(classCss) < 0) {
list.push(classCss)
};
}
);
});
let listOrdered = list.sort();
return listOrdered;
}
let listClassCss = getListClassCss();
console.info(listClassCss);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment