I have a script that uses $(document).ready, but it doesn’t use anything else from jQuery. I’d like to lighten it up by removing the jQuery dependency.
How can I implement my own $(document).ready functionality without using jQuery? I know that using window.onload will not be the same, as window.onload fires after all images, frames, etc. have been loaded.
There is a standards based replacement,
DOMContentLoadedthat is supported by over 99% of browsers, though not IE8:jQuery’s native function is much more complicated than just window.onload, as depicted below.