How do I make an HTML button not reload the page

Ankur picture Ankur · Dec 10, 2009 · Viewed 268k times · Source

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.

Answer

Jafar Rasooli picture Jafar Rasooli · Dec 24, 2013

there is no need to js or jquery. to stop page reloading just specify the button type as 'button'. if you dont specify the button type, browser will set it to 'reset' or 'submit' witch cause to page reload.

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