I have a requirement that states to use only plain JavaScript and not jQuery. I need to initialize some variables(using some function) as soon as the DOM is loaded and not when the page has fully loaded. In short it should not wait for the whole page to load. In jQuery it can be very easily done using document.ready()
function.
Is it possible to implement it in JavaScript using any function?
document.ready()
is executed as soon as the DOM loaded. If you just want to execute some code when the page starts loading, put it in thehead
. If you would provide some example, we could help you better. BUt if you really want the same functionality, just put the script at the end of thebody
.