Hide the “created by” and “last modified by” on a SharePoint 2013 dispform with JavaScript

A client was creating a public site and wanted to show a list of documents with the “more info” link.
The visitors shouldn’t see the person who has created and modified the document, so we need to hide that information from the dispform.

This is very easy with JavaScript and jQuery. A quick look with the “Internet Explorer Developer tool” shows us that the bottom lines are just span elements. They have unique ID’s but they are very long and unique per library. The “td” element which capsulates the span has an easy to read id though!

ID’s for the elements

These are the ID’s for the elements:

onetidinfoblock1: created on this date x by person y
onetidinfoblock2: last modified on this date x by person y
onetidinfoblockV: version x

Getting the element ID
Getting the element ID

Hide the fields with JavaScript

Edit the dispform (via the browser by clicking on the cog – edit page) and add a script editor webpart. Make sure the script editor web part is the bottom one! Add this code in the script editor, save and test!


<script type=text/javascript>
//hide created
document.getElementById("onetidinfoblock1").innerHTML=" ";
//hide last modified
document.getElementById("onetidinfoblock2").innerHTML=" ";
//hide version
document.getElementById("onetidinfoblockV").innerHTML=" ";
</script>

Hide the fields with jQuery

Edit the dispform (via the browser by clicking on the cog – edit page) and add a script editor webpart. Make sure the script editor web part is the bottom one! Add this code in the script editor, save and test!
Don’t forget to refer to the jQuery file!


<script type=text/javascript>
//hide created
$("[id='onetidinfoblock1']").hide();
//hide last modified
$("[id='onetidinfoblock2']").hide();
//hide version
$("[id='onetidinfoblockV']").hide();
</script>

The fields are hidden
The fields are hidden

About: Marijn

Marijn Somers (MVP) has over 14 years experience in the SharePoint world, starting out with SP2007. Over the years the focus has grown to Office 365, with a focus on collaboration and document management. He is a business consultant at Balestra and Principal Content Provider for "Mijn 365 Coach" that offers dutch employee video training. His main work tracks are around user adoption, training and coaching and governance. He is also not afraid to dig deeper in the technicalities with PowerShell, adaptive cards or custom formatting in lists and libraries. You can listen to him on the biweekly "Office 365 Distilled" podcast.


4 thoughts on “Hide the “created by” and “last modified by” on a SharePoint 2013 dispform with JavaScript”

  1. how can I add a if statement to this? hide certain fields only when the value of a certain field is equal to x let’s say..Thanks in advance

  2. I have full control and i did the same and its working for me. But people have contribute level access. They are able to see “Created by” and “Modified by”. So need to hide permanently.

    1. Since parts of this list are dynamic JS is not the best choice here for this, CSS is because all of the views are held within the same container (in most cases):

      One script editor needed, just select one of the views:

      #onetidinfoblock1, #onetidinfoblock2 {
      display: none;
      }

      Also, those posting that the columns just need to be ticked off are not really listening or testing.

Leave a Reply

%d bloggers like this: