javascript - How to prevent buttons from submitting forms - Stack Overflow

PHOTO EMBED

Wed Jul 20 2022 19:35:13 GMT+0000 (Coordinated Universal Time)

Saved by @kalehm #html

You're using an HTML5 button element. Remember the reason is this button has a default behavior of submit, as stated in the W3 specification as seen here: W3C HTML5 Button

So you need to specify its type explicitly:

<button type="button">Button</button>
content_copyCOPY

https://stackoverflow.com/questions/932653/how-to-prevent-buttons-from-submitting-forms