3

I want to change the "New Item" text into "Yeni Ekle". I viewed the source of the list from browser. Here is the part of the New Item;

<a id="idHomePageNewItem" ...........>
  <span ...>
    <img id="idHomePageNewItem-img" ....></img>
  </span>
  <span>  new item  </span>
</a> 

And here is my code for change the text. But it doesn't work. Why doesn't it work?

Updated:

<asp:content contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">
    <SharePoint:RssLink runat="server"/>
    <SharePoint:scriptlink ID="ScriptLink" Name="SP.js" runat="server" OnDemand="true" Localizable="false"></SharePoint:ScriptLink> 
    <script type="text/javascript" src="/../../../Style Library/SolidQ-SPS-JS.js"></script>
    <script type="text/javascript">
        ExecuteOrDelayUntilScriptLoaded(ChangeText,"sp.js");
        function ChangeText() {
          document.getElementById('idHomePageNewItem').getElementsByTag("span")[1].innerHTML="Yeni Ekle";
        }
    </script>
</asp:content>

2 Answers 2

4

Try change getElementsByTag to getElementsByTagName as that is the valid Javascript DOM selector

So the solution script is:

<script type="text/javascript">
    ExecuteOrDelayUntilScriptLoaded(ChangeText,"sp.js");
    function ChangeText() {
      document.getElementById('idHomePageNewItem').getElementsByTagName("span")[1].innerHTML="Yeni Ekle";
    }
</script>
0
2

There could be multiple reasons, either your javascript is executing before the control text has been rendered, or your selection method is not correct.

Have you tried triggering the function manually after the page has fully loaded from the console?

11
  • Doesn't $().ready trigger the function?
    – e.ozmen
    Commented Mar 15, 2013 at 8:30
  • Well it does, but it has a tendency in sharepoint to trigger before all sharepoints javascript functions has executed. I usually use ExecuteOrDelayUntilScriptLoaded() and specify sp.js or sp.ui.socialribbon.js as the script to wait for just to make sure Commented Mar 15, 2013 at 8:37
  • I updated the javascript part. It doesn't work. Did I write it wrong?
    – e.ozmen
    Commented Mar 15, 2013 at 8:47
  • Yes, you should only write the functions name as the first parameter in ExecuteOrDelay.. Like ExecuteOrDelayUntilScriptLoaded(ChangeText,"sp.js"); Commented Mar 15, 2013 at 8:50
  • Should I import anything for sp.js?
    – e.ozmen
    Commented Mar 15, 2013 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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