I have an HTML button in my SharePoint hosted app like this:

<input type="button" id="btnSubmit" value="Test"/>

and I tried

<button id="btnSubmit">Test </button>

But it is always refreshing until I remove all the code from SharePoint and leave it as regular HTML page.


Your buttons are in a SharePoint FORM, so when you add a button the click event is bubbling up to the FORM, and the FORM is submitted.

You have to add JavaScript code to stop that from happing with




See: https://codeplanet.io/preventdefault-vs-stoppropagation-vs-stopimmediatepropagation/

  • thanks Danny, but doesn't this happen only with <button> not with <input> ? – Shang Hui Feb 23 '15 at 13:17
  • Button is default of type submit, use type="button" as in your first example and you will be fine, not need for the JS – eirikb Feb 23 '15 at 21:24
  • thanks eirkib, I noticed that when I remove the sharepoint content place holders and just leave the <web part pages> the refresh goes away, but when I do that on regular page of sp, it's back. any idea? – Shang Hui Feb 23 '15 at 22:35
  • Check the resulting markup, if the <button> resides inside a <form> it will trigger form submit on click – eirikb Feb 23 '15 at 22:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.