Answers for "html dont reload page when clicking button"

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
1

reload pageon button click

<button type="button" onClick="window.location.reload();">Close</button>
Posted by: Guest on March-19-2020

Code answers related to "html dont reload page when clicking button"

Code answers related to "Javascript"

Browse Popular Code Answers by Language