How to suppress unexpected submit by button click

How to suppress unexpected submit by button click

  

Hi, I'm creating Web app using jQuery.

Using jQuery dom method, I added the <button> element that trigger view change locally(like SPA).

But when I clicked the <button>,  the form was submitted  unexpectedly and page was recreated.

I suppose the submit event listener is bound to <button> (please refer to the bellow image).

Please give me some advice about how to disable submit action or workaround.

Thanks!!


Solution

Hi,

You have to set the button type, type='button' (submit is the default).

Solution

Thank for your specific advice!!

Everything works well.

João Neves wrote:

Hi,

You have to set the button type, type='button' (submit is the default).