Good day. There is a menu button
`<div class="grid__menu"> <i class="material-icons md-48 menu__button">dashboard</i> </div>` when I click on that, I want to change the menu__button class to menu__button--active can change the class menu__button
var activeModificator = '--active'; function toggle (className, active) { var name = className.replace(/\./g, ''); var activeName = (active === undefined) ? activeModificator : active; if (name.indexOf(activeName) == -1) { document.querySelector(className).classList.add(name+activeModificator); document.querySelector(className).classList.remove(name); } else { document.querySelector(className).classList.add(name); document.querySelector(className).classList.remove(name-activeModificator); } } But in the function I need to pass the name of the class, which must be taken from the line <i class="material-icons md-48 menu__button">dashboard</i>
How do I get the class name from document.querySelector(".menu__button"); ? After all, there will first be menu__button , and then menu__button--active ? And after the first change the class will be different. What is the algorithm at all? No jQuery