Document. Ready and Executeordelayscriptloaded

I have a dilemma - my javascript code needs to be executed when the DOM is ready. However, at the same time I need to be able to hook up to the load event of another script. So hypothetically speaking I need something like this:

 ExecuteOrDelayUntilScriptLoaded(getData, "sp.js");


 function getData() {


       (document.ready(function() {

            //my code to get data from sharepoint list.  
       }));

 }

Only the latter does not seem to work.

Please suggest!

3 Answers

Why not to do it like this?

 $(document).ready(function() {
    ExecuteOrDelayUntilScriptLoaded(function getData(){
        //your code to get data from sharepoint list.  
    }, "sp.js");
 });
1

Try

$(document).ready(function() {
    $.getScript('sp.js', function() {
        //your code to get data from sharepoint list.
    });
});

For even more control over script loading, try a script loader like the simple and lightweight yepnope.js or the more complex LABjs.

2

If you are using jQuery, MooTools, or any other library - there is a standard function you can hook into, which checks if the DOM and your assets are loaded.

For example, in jQuery:

Your Answer

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

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest