+ 1
What's the difference between using a javascript in the head and within a body?
3 Réponses
+ 12
@Brains : There still can be problems if we add the <script> tag in body :p ..It should be placed at the bottom (just above the </body> )
Alternatively, We can use :-
window.onload = function (){
// code here
}
+ 8
I think you using a script tag.well when you write a script in the head it runs before the body has even loaded,so expect errors!
writing a script in the body however allows all html code positioned before it in the body to run before executing.
hope I helped
+ 5
I quote " writing a script in the body however allows all html code positioned before it in the body to run before executing. "
This means any element positioned before the script tag is declared in the body loads soo the script must be at the end