Q. The script tag must be placed in
β
Correct Answer: (B)
head and body
Explanation:
In HTML, the <script> tag can be placed in both the <head> and <body> sections:
In the <head> section:
- If the script is needed before the page loads (e.g., setting up configurations or defining functions).
- Example:
In the <body> section:
- Commonly used for scripts that interact with page elements to ensure the document is fully loaded.
- Example:
In both <head> and <body>:
- A mix of both can be used depending on the scriptβs purpose.
Incorrect options:
- (C) title and head β <script> is not allowed inside <title>.
- (D) all of the mentioned β Since <script> is not valid inside <title>, this option is incorrect.
<body>
<script>
console.log("Script in body");
</script>
</body>
<head>
<script>
console.log("Script in head");
</script>
</head>