when dom is ready javascript code example
Example 1: javascript wait for document load
document.addEventListener("DOMContentLoaded", function(event) {
//do work
});
Example 2: js dom ready function
<!doctype html>
<html>
<head>
</head>
<body>
Your HTML here
<script>
// self executing function here
(function() {
// your page initialization code here
// the DOM will be available here
})();
</script>
</body>
</html>