Last active
December 13, 2018 16:55
-
-
Save edjw/c1737f1f2651d86760b32803553b8560 to your computer and use it in GitHub Desktop.
Get the class names of a html element that you click on
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
"use strict"; | |
document.addEventListener("click", function (event) { | |
event.preventDefault(); | |
const allClasses = Array.from(event.target.classList).join("."); | |
const classes = "." + allClasses; | |
if (classes == ".") { | |
console.log("No classes found"); | |
} else { | |
console.log(classes); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment