Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.


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.

share|improve this question
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 at 13:30
    
It should be inside dom.ready –  Nk SP Oct 7 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 at 13:36
    
it works! I used ExecuteOrDelayUntilScriptLoaded. Thanks –  Nk SP Oct 7 at 13:45

1 Answer 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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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