Categories
HTML

How to prevent refresh of page when button inside form clicked?

Spread the love

Sometimes, we want to prevent refresh of page when button inside form clicked.

In this article, we’ll look at how to prevent refresh of page when button inside form clicked.

How to prevent refresh of page when button inside form clicked?

To prevent refresh of page when button inside form clicked, we set the type attribute of the button to button.

For instance, we write

<button type="button">Click</button>

to add a button in the form with the type attribute set to button to prevent refresh of the page when we click on the button.

Conclusion

To prevent refresh of page when button inside form clicked, we set the type attribute of the button to button.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *