Friday 13 December 2013

Javascript : Where to Place in HTML

Javascript (JS):
You can include JavaScript code anywhere in an HTML document.
preferred ways are :

-> <head> .... </head> section
-> <body> .... </body> section
-> Use External file and include it in <head>..</head> section

JavaScript placed in <head>...</head> section:

-> if User want to user event such as click , change etc .. You have to
   place script in <head> section


JavaScript placed in <body>...</body> 

-> When you want script to generate contents in webpage place
   script in <body> section


JavaScript placed in External File :

-> As We know javascript code may require more than one html pages
   so user can create an external JS file and use it in various
   HTML pages
-> Also its reduces the complexity
    NOTE : save the javascript file with .js extension

No comments:

Post a Comment