Javascript simple add class remove class -
<div onclick="myfunction();"> click me</div> <div id="nav" style="" class="hide"> <ul> <li>sample</li> <li>sample</li> <li>sample</li> </ul> </div>
function myfunction (){ if ("show"){ document.getelementbyid('nav').style.display='none'; } else if ("hide"){ document.getelementbyid('nav').style.display='none'; } }
onclick click me btn, want show & hide "nav". using addclass remove class.
please me in pure javascript.
thanks.
maybe work better ?
<div id="btn"> click me</div> <div id="nav" style="" class="hide"> <ul> <li>sample</li> <li>sample</li> <li>sample</li> </ul> </div> <script> var menu = document.getelementbyid('nav'); document.getelementbyid('btn').onclick = function() { if (menu.classname == "hide"){ menu.classname = "show"; } else { menu.classname ='hide'; } } </script> <style> .show { display: inherit; } .hide { display: none; } </style>
Comments
Post a Comment