I am using this script to hide 'Edit' button from SharePoint ribbon on my custom webpart's ascx page and calling it in the page load:

   function hideEdit() 

  var edit = document.getElementById("Ribbon.ListForm.Manage,EditItem-Large");

  edit.style.display = "none";
        alert ("I am an alert box!");



and I am getting two annoying errors:

1)SCRIPT1004: Expected ';'

2)SCRIPT5007: Unable to get property 'style' of undefined or null reference

I have checked like 100 times, there is no semicolon missing. Any clue whats happening here?

  • 1
    how about edit is undefined? maybe because "Ribbon.ListForm.Manage,EditItem-Large" does not look like a valid selector. Please try to learn some JS basics (like debugging). This would have made this mistake obvious. – Mx. Feb 9 '16 at 13:41
  • so what shall i do in this case @Mx. – Revenant_01 Feb 9 '16 at 13:42
  • i just checked in chrome , it gives "Uncaught SyntaxError: Unexpected token var" error – Revenant_01 Feb 9 '16 at 13:46
  • Your problem is really basic and hasnt anything to do with SharePoint. Try to get more knowledge about JS itself and you will find this errors dont appear anymore. – Mx. Feb 9 '16 at 13:55

Seems like you have entered the selector wrong. THere is never a comma in a selector. Instead of using Javascript, you can achieve this by CSS. You can use the following css to hide the Edit button in the Ribbon.

    display: none !important;
  • on SharePoint always try to go CSS before JavaScript css style is applied right away, JavaScript will load and then apply you'll see the blinking (good answer +1) – Mike Aug 20 at 15:06

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.