Answers for "avoid button onclick reload page"

1

how to make a button not reload on click

<button id="button">Button</button> <!-->Creates a new button.</!-->
<script>
	const button = document.querySelector("#button"); //Finds the button by id.
	button.addEventListener("click", e => { //Runs the function (doesn't have to be an arrow function, just a function.) whenever said button is clicked.
      e.preventDefault(); //Stops said button from reloading the page.
    }
</script>
Posted by: Guest on July-05-2021
0

stop refreshing page on button click

<form method="POST">
    <button name="data" onclick="return getData()">Click</button>
</form>
Posted by: Guest on September-06-2021

Code answers related to "avoid button onclick reload page"

Browse Popular Code Answers by Language