I've been trying to figure this out for a couple hours now and can't seem to find an answer that will work or is for the version I'm using so here it is:

I am using SharePoint 2016 online I believe is what it would be. I have SharePoint designer 2013 to customize my page.

I have my AllItems.aspx* open and I am trying to customize the button that says "New Item" on a custom list to say "New person" instead. I know I have to do it with javascript (or that's the way it seems) but I cannot figure out where to put it and what exactly the javascript would be. Any help would be great. Thanks.

up vote 5 down vote accepted
  • Open your Custom List via Browser.
  • Edit the Page.
  • Add Script Editor.
  • Edit Snippet.

Add the following code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>

<script>
$(document).ready(function(){

var spans = document.getElementsByTagName("span");
for(var i=0;i<spans.length; i++) {
    if(spans[i].innerHTML == "new item") { 
        spans[i].innerHTML = "new person";  
        break;                                  
    }
}

});
</script>

[Output]

enter image description here

  • If I have multiple views will it also change it for those? – Eric Braun Sep 13 '16 at 13:38
  • @EricBraun Yes, it will also change "new item" to "new person" for all views . you need only add the above script editor for "allitems.aspx" page – Mohamed El-Qassas MVP Sep 13 '16 at 16:19

Here is some code you could use in a Script Editor Webpart or Content Editor Webpart:

<script>
document.addEventListener("DOMContentLoaded",
    function () {
        ExecuteOrDelayUntilScriptLoaded(function () {
            var ReRenderListView_old = ReRenderListView
                ReRenderListView = function (b, l, e) {
                ReRenderListView_old(b, l, e)
                changeText()
            }
        }, "inplview.js")
        changeText()
    }
);

function changeText(){
    var element = document.querySelector('#idHomePageNewItem span:nth-child(2)')
    element ? (element.innerHTML = "New Person") : null
}
</script>

This code does not require jQuery and it assumes that there is only one "New Item"-button on the page. Furthermore, this script will also change the "New Item"-text gain after you went into Quick Edit mode and back.

Using java script to change text for single web part:

<script type="text/javascript">
    window.onload=function(){
    var spans = document.getElementById('idHomePageNewItem').getElementsByTagName('span');
    spans[1].innerHTML="New Person";
}
</script>

Just note that for PowerApps, if you create a PowerApps form, this "trick" will fail. The aspx page (NewForm) is labeled the same but the classic view vs the newer view (the one that hosts the PowerApps form) does not have this script option on that view page. I'm assuming the work around for this would be to add the WebPart in the template/masterpage. Frustrating as you end up with two forms (one that you don't want because it shows all your columns - not always a desire), and the UX is dependent on the type of SharePoint view the user chooses, which you've no control over - one will say "New Item" (the one with the PowerApps form), the other will say "New Person" (assuming you added the script) on the view that has the "old fashion" view. Maybe MS could just add a variable for "New Item" and make it something we can assign values to??? As they say, "down with idiot values". HTH.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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