Where should I place my <script> code in my HTML document?

Mathias Neuhaus

Short answer:
Place it wherever you need it.

Long answer:
JavaScript code is loaded - and immediately executed (!!), if it's not the definition of a variable or function - in the same sequence it appears in the source.
It's common use to declare all JavaScript functions beforehand within the <head> section of an HTML-document. This way all functions will be "ready to run", when the <body> section is loading.
A good point to start initialization functions is the onLoad-property of the <body>-tag.

0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact