1//two ways of executing JS code after page is loaded, use "DOMContentLoaded" when able
2
3document.addEventListener("DOMContentLoaded", function(){
4 //dom is fully loaded, but maybe waiting on images & css files
5});
6
7window.addEventListener("load", function(){
8 //everything is fully loaded, don't use me if you can use DOMContentLoaded
9});
1$(document).ready(function(){
2 $("button").click(function(){
3 $("p").slideToggle();
4 });
5});
1// without jQuery (doesn't work in older IEs)
2document.addEventListener('DOMContentLoaded', function(){
3 // your code goes here
4}, false);
5
1document.addEventListener("DOMContentLoaded", function(event) {
2 //we ready baby
3});