How can I add and remove an active class to an element in pure JavaScript

前端 未结 9 1184
被撕碎了的回忆
被撕碎了的回忆 2020-12-17 20:29

I am trying to make a navigation menu I did all the HTML and CSS when come to javascript I am struck in the middle I am able to add a class to the

9条回答
  •  旧时难觅i
    2020-12-17 20:48

    Below should help.

    //Remove all classes by ID
    document.getElementById("elementIdHere").className = "";
    //If you wish to keep some classes on the element, use below
    document.getElementById("elementIdHere").className = "keepClass";
    

提交回复
热议问题