0

Where JavaScript typically placed? Is it is under body tag or head tag? State with reason.

in adding JavaScript to web page section, I get confuse when that same question asked me twice with different answer.

8th Jul 2017, 7:41 PM
Rudrasish Sengupta (RS)
Rudrasish Sengupta (RS) - avatar
2 Réponses
+ 9
You can place it both in body and head tag, this is the answer to your challenge question. Main difference is that placing it at the end of your <body> tag (as external file or inside your ".html" file) you will have all your DOM elements loaded. Placing it in the <head> tag (as external file or inside your ".html" file) you should use an onload (or similar) event to manipulate DOM elements. Generally, as common practice it is placed in the <head> section.
8th Jul 2017, 7:58 PM
Maz
Maz - avatar
9th Jul 2017, 1:48 AM
Sandeep Chatterjee