Im using the js function shown below to make a part of page disappear when user clicks on the button. but when i click on the button, the part disappears, but page reloads. why is it like this?

<button id="myDIV" onclick="fncShowHide()">Try it</button>

window.fncShowHide = function() {
   document.getElementById("idein").className = "display-none";

it happens because the button is submitting a form (most probably) try adding this to your html

<button id="myDIV"  type="button" onclick="fncShowHide()">Try it</button>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.