What is the non-jquery equivalent of $(document).ready()?
I don't think javascript has that function inbuilt. It is jQuery specific.
The original question was "What is $(document).ready() in javascript?"
In plain vanilla JavaScript, with no libraries? It's an error. $
is simply an identifier, and is undefined unless you define it.
jQuery defines $
as it's own "everything object" (also known as jQuery
so you can use it without conflicting with other libraries). If you're not using jQuery (or some other library that defines it), then $
will not be defined.
Or are you asking what the equivalent is in plain JavaScript? In that case, you probably want window.onload
, which isn't exactly equivalent, but is the quickest and easiest way to get close to the same effect in vanilla JavaScript.
The nice thing about $(document).ready()
is that it fires before window.onload
. The load function waits until everything is loaded, including external assets and images. $(document).ready
, however, fires when the DOM tree is complete and can be manipulated. If you want to acheive DOM ready, without jQuery, you might check into this library. Someone extracted just the ready
part from jQuery. Its nice and small and you might find it useful: