I am trying to call a Javascript function through a button I posted on my sharepoint page like so

<button type="button" onclick="myFunction(); return false;">Button</button>

But after I save the page and view the source again the code gets changed to this

<button type="button">Button</button>​​​

It totally removes the onClick event. Why is this? How can I fix it?

I have tried in the html editor, embedded code editor, and even tried to change it to input type=button all result in same behavior

2 Answers 2


The embedded source editor will strip the onclick event.

You will need to use a Content editor webpart or an HTML Form webpart.


  • Hey yes this worked great!
    – Sudosu0
    Commented Jul 23, 2018 at 13:06

I tested as your description, and could reproduce this issue.

To avoid this issue, I suggest you Content Editor web part or Script Editor Web part. enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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