0

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!"); } _spBodyOnLoadFunctionNames.push("hideEdit"); 

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?

11
  • stackoverflow.com/questions/988363/… Commented Feb 9, 2016 at 13:30
  • 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. Commented Feb 9, 2016 at 13:41
  • so what shall i do in this case @Mx. Commented Feb 9, 2016 at 13:42
  • i just checked in chrome , it gives "Uncaught SyntaxError: Unexpected token var" error Commented Feb 9, 2016 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. Commented Feb 9, 2016 at 13:55

1 Answer 1

1

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.

#Ribbon\.ListItem\.Manage\.EditProperties-Large { display: none !important; } 
1
  • 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) Commented Aug 20, 2019 at 15:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.