Answers for "parent class and add element addclass"

0

parent class and add element addclass

// html <div class="parentElm" id="addActive"></div>

// js
function toggleClass(){
  // get the properties of an element
  var element = document.getElementById("addActive");
  
//  check if the element have class list
  if (element.classList) {
    // add active class if true
   element.classList.toggle("active");
  } else {
   var classes = element.className.split(" ");
   var i = classes.indexOf("active");
  }
 }
Posted by: Guest on July-16-2020

Code answers related to "parent class and add element addclass"

Code answers related to "Javascript"

Browse Popular Code Answers by Language