How do I make an HTML button not reload the page Ask Question

How do I make an HTML button not reload the page Ask Question

I have a button (<input type="submit">). When it is clicked the page reloads. Since I have some jQuery hide() functions that are called on page load, this causes these elements to be hidden again. How do I make the button do nothing, so I can still add some action that occurs when the button is clicked but not reload the page.

ベストアンサー1

There is no need to use JS or jQuery. to stop the page to reload, just specify the button type as 'button'.

If you don't specify the button type, the browser will automatically set it to 'reset' or 'submit' which causes the page to reload.

<button type='button'>submit</button> 

おすすめ記事