Sometimes, we want to prevent refresh of a page when a button inside the form is clicked with HTML.
In this article, we’ll look at how to prevent refresh of a page when a button inside the form is clicked with HTML.
How to prevent refresh of a page when a button inside the form is clicked with HTML?
To prevent refresh of a page when a button inside the form is clicked with HTML, we set the type
attribute of the button to button
.
For instance, we write
<button name="data" type="button" onclick="getData()">Click</button>
to add the type
attribute and set it to button
to prevent refresh of a page when a button inside the form is clicked.
Conclusion
To prevent refresh of a page when a button inside the form is clicked with HTML, we set the type
attribute of the button to button
.