1$('.click-class').click(function() {
2 $('.class-toggle').toggle();
3 $('.class-toggle').toggleClass('add-class');
4})
1var menu = document.querySelector('.menu') // Using a class instead, see note below.
2menu.classList.toggle('hidden-phone');
1// html <div class="parentElm" id="addActive"></div>
2
3// js
4function toggleClass(){
5 // get the properties of an element
6 var element = document.getElementById("addActive");
7
8// check if the element have class list
9 if (element.classList) {
10 // add active class if true
11 element.classList.toggle("active");
12 } else {
13 var classes = element.className.split(" ");
14 var i = classes.indexOf("active");
15 }
16 }