Question and answer is powered by AnsPress.io
I need my HTML element class name while clicking on this element. if my HTML div like:
<div class="main-header">My code</div>
I want to get the class name while I will click on it.
$('body').on("click", ".main-header", function() { console.log("Class Name"); });
How can I get the class name here?
If you want to get the class name by clicking, apply this code
$('body').on("click", ".main-header", function() { var myClass = this.className; console.log(myClass); });
Output: main-header