Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

document.ready and ExecuteOrDelayScriptLoaded

Writer Emily Wong

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

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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