I wish to hide the edit items ribbon in one of the webpart pages where i am displaying a list view webpart.
I found the solution in this question, I am able to hide the ribbons.
<script type="text/javascript">
function hideEdit() {
var edit = document.getElementById("Ribbon.ListForm.Display.Manage.EditItem-Large");
edit.style.display = "none";
}
_spBodyOnLoadFunctionNames.push("hideEdit");
</script>
The problem is , i am getting some java-script errors in my console when i use the code
The error details are below
MyPage.aspx:751 Uncaught TypeError: Cannot read property 'style' of null
at hideEdit (MyPage.aspx:751)
at eval (eval at ProcessOnLoadFunctionNames (init.js:1), <anonymous>:1:34)
at ProcessOnLoadFunctionNames (init.js:1)
at ProcessDefaultOnLoad (init.js:1)
at NotifyEventAndExecuteWaitingJobs (init.js:1)
at NotifyScriptLoadedAndExecuteWaitingJobs (init.js:1)
at $_global_core (core.js:1)
at core.js:1
I tried to manually locate the element in the console using
document.getElementById("Ribbon.ListForm.Display.Manage.EditItem-Large")
and
$('#Ribbon.ListForm.Display.Manage.EditItem-Large')
both are returning null
and undefined
. I can't figure out this error and how is the above code working?
- Even if i change the id to something else i was able to hide the ribbons. why is it working?
- If the above queries are returning null it means the code is incorrect right?
Where to get the proper ids of these ribbons?
Did MS changed the ids in SharePoint-Online?
UPDATE
The above code achieves the desired functionality but i can't comprehend how. because the element is not present in any of my source code or in console.
So, please explain why it works even though element is absent and way to avoid the error.
EDIT:
I tried escaping the .
using \.
but still the element is not present