0
What's the difference between putting script in <head> and <body>?
3 Réponses
+ 2
I don't think it'll change anything as far as how the program runs.
+ 1
there is no significant difference when you put script in head it is one place and does not get mixed there with webpage.
but in this case sometime the element it is referring to hasn't yet loaded so scripts are either placed in body after elements which take time in loading slowly or all the scripts is put in document.onload listener in this way they run only when document is loaded. or listener can be attached to the elements
+ 1
@Sandeep Chatterjee is right, scripts are generally placed at the END of <body> - simply due to the fact that the scripts run when loaded. If this is in <head> then the script will run early in the loading process and can cause delays in the page loading through.