Sometimes, we want to prevent buttons from submitting forms with HTML.
In this article, we’ll look at how to prevent buttons from submitting forms with HTML.
How to prevent buttons from submitting forms with HTML?
To prevent buttons from submitting forms with HTML, we can set the type
attribute of a button to button
.
For instance, we write
<button type="button">Button</button>
to add a button with type
attribute set to button
to stop it from submitting the form that it’s in when we click on it.
Conclusion
To prevent buttons from submitting forms with HTML, we can set the type
attribute of a button to button
.