The difference between javascript execution before and after elements

web front end four thousand eight hundred and twenty-six 5 years ago (2019-08-25)

When writing native js, we found that, script It cannot be executed before the dom element. It needs to be placed after the dom element to be effective. Because the js is executed immediately after loading, we put the code in the window.onload function body to let the page be loaded completely before execution.

 window.onload = function(){ //Execute when page loading is complete }

The jQuery code placed before and after the page element has no impact on the execution effect.