Skip to content

Instantly share code, notes, and snippets.

@qubodup
Created July 2, 2022 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save qubodup/83e36eac3c4725ee34ea22720821eb98 to your computer and use it in GitHub Desktop.
Save qubodup/83e36eac3c4725ee34ea22720821eb98 to your computer and use it in GitHub Desktop.
get all classes and ids used by element
var classes = []
$('div').each(function() {
if (this.hasAttribute('class')) {
classes = classes.concat( $(this).attr("class").split(/\s+/) );
}
});
classes = [...new Set(classes)];
var classString;
for (const c of classes) {
classString += '.'+c+',\n';
}
console.log(classString);
var ids = []
$('div').each(function() {
if (this.hasAttribute('id')) {
ids = ids.concat( $(this).attr("id").split(/\s+/) );
}
});
ids = [...new Set(ids)];
var idString;
for (const c of ids) {
idString += '#'+c+',\n';
}
console.log(idString);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment