can anyone tell me ho do i write code for add remove class on click in navigation | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

can anyone tell me ho do i write code for add remove class on click in navigation

jjx

11th Apr 2017, 9:10 AM
Binod Nakhan
Binod Nakhan - avatar
2 Answers
+ 1
// to add class: var d = document.getElementByTagName("nav"); d.className += " newclass"; // to remove class: d.className = d.className.replace ("newClass","");
11th Apr 2017, 9:45 AM
Calviղ
Calviղ - avatar
0
I'm using w3.js library, in which it's just w3.addClass("#id","classname"); and w3.removeClass("#id","classname"); HTML: <head> <link rel="stylesheet" href="example.css> </head> <body> <nav> <div id="nav1" onclick="w3.addClass("#nav1", "navClicked")">Something in here</div> </nav> <script src="w3.js"></script> </body>
11th Apr 2017, 9:41 AM
Kuba Nawieśniak
Kuba Nawieśniak - avatar