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.

4
  • 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/… Commented Oct 7, 2014 at 13:30
  • It should be inside dom.ready
    – Nk SP
    Commented Oct 7, 2014 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.) Commented Oct 7, 2014 at 13:36
  • it works! I used ExecuteOrDelayUntilScriptLoaded. Thanks
    – Nk SP
    Commented Oct 7, 2014 at 13:45

1 Answer 1

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 and acknowledge you have read our privacy policy.

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