I want to make a Javascript function where it reads the class of the selected element and adds the class active
. How can I get the class of the HTML element where my function is?
I tried to make an Javascript function with document.getElementsByClassName(class)
, but that doesn't work.
function menuicon(){
var className = $('div').attr('class');
className.$(className).addClass("active");
}
<section class="menubar">
<div class="menuicon" onclick="classAdd()">
<span></span>
<span></span>
<span></span>
</div>
</section>
<section class="home">
<button class="hbutton" onclick="classAdd()"></button>
</section>
I want that the Javascript function reads out the class of the HTML element where the function is placed in.