Created
July 2, 2022 14:00
-
-
Save qubodup/83e36eac3c4725ee34ea22720821eb98 to your computer and use it in GitHub Desktop.
get all classes and ids used by element
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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