0
can anyone tell me ho do i write code for add remove class on click in navigation
jjx
2 Answers
+ 1
// to add class:
var d = document.getElementByTagName("nav");
d.className += " newclass";
// to remove class:
d.className = d.className.replace ("newClass","");
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>