Skip to content

Small javascript utility to wait for jquery or other libraries to load before executing functions.

License

Notifications You must be signed in to change notification settings

drosko/wait-for-it

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Wait For It

Small javascript utility to wait for jquery or other libraries to load before executing functions.

The most likely use case for this is if you are using a cms which loads a library such as jQuery near the end of the body tag, and the javascript you need to execute comes before that definition (ie. in a blog post).

###How to Use

By default this utility waits for jQuery, however you can pass a string as the first argument to wait for whatever variable you want.

Default:

wfi(function(){
  console.log('jQuery is now defined');
});

Example waiting for angular to be defined:

wfi('angular', function(){
  console.log('angular is now defined, do stuff');  
});

You can pass multiple functions, they will get called in succession:

wfi('angular', 
  function(){
    console.log('angular is now defined, do stuff');  
  }, 
  function(){
    console.log('do some more stuff after that');
  }
);

About

Small javascript utility to wait for jquery or other libraries to load before executing functions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published