0


I have an issue with this simple Javascript code into a SharePoint list view page.

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
    $(document).ready(function(){
        $("#inplaceSearchDiv_WPQ2").append("<p>myTest</p>");
        //do stuff with id
    });
</script>

This code is running in IE but not in Chrome, why?
I am using a Script editor web part.

  • 2
    Probably because it executes in Chrome before your DOM has finished loading. Take a look here for steps to mitigate: blog.tallan.com/2012/10/01/… – Robert Lindgren Oct 7 '14 at 13:30
  • It should be inside dom.ready – Nk SP Oct 7 '14 at 13:34
  • But jQuery's DOM ready does not take in to account DOM objects renders client side (which are a few in SharePoint, hence the existence of the specific SP.SOD.executeFunc etc.) – Robert Lindgren Oct 7 '14 at 13:36
  • it works! I used ExecuteOrDelayUntilScriptLoaded. Thanks – Nk SP Oct 7 '14 at 13:45
1

In Chrome the code was exectued before the load of the DOM.
I used this to solve my problem:

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
    $(document).ready(function(){
        ExecuteOrDelayUntilScriptLoaded(myFunc, "sp.js");
    });

    function myFunc(){
        $("#inplaceSearchDiv_WPQ2").append("<p>myTest</p>");
        //do stuff with id
    }
</script>

Thanks to @Robert Lindgren

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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