1

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 does disappear, but then page reloads. why is it like this?

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

<script>
window.fncShowHide = function() {
   document.getElementById("idein").className = "display-none";
}
</script>
kiasaty
  • 187
  • 1
  • 11

2 Answers2

4

See What's the standard behavior when < button > tag click?.

Return false from the onclick handler to prevent any default browser action.

<button id="myDIV" onclick="fncShowHide(); return false;">Try it</button>
Community
  • 1
  • 1
Radek Pech
  • 3,032
  • 1
  • 24
  • 29
0

?

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

window.other_ = function() {
   document.getElementById("idein").style.display = "none";
}
.display-none{
display:none;
}
<button id="myDIV" onclick="fncShowHide(); return false;">Try it</button>
<div id="idein">BYEEEEEEEEEEEEEEEEEEEEEEEEEEE!</div>
<script>

</script>
Community
  • 1
  • 1