-3

Client-side Javascript can appear where within an HTML document?

A. Between the <head> and </head> tags

B. Between the <body>and </body> tags

C. Both of the above

D. None of the above

N J
  • 27,217
  • 13
  • 76
  • 96
jay165
  • 13
  • 4

3 Answers3

1

Here are codes that are placed in the different parts of the HTML. Ever variation will run no matter where the script tag is placed.

1.

<html>
<head>
    <title>Foo</title>
    <script type="text/javascript">
        alert("hello world");
    </script>
</head>
<body>

</body>
</html>

2.

<html>
<head>
    <title>Foo</title>

</head>
<body>
    <script type="text/javascript">
        alert("hello world");
    </script>
</body>
</html>

3.

<html>
<head>
    <title>Foo</title>

</head>
<body>

</body>
    <script type="text/javascript">
        alert("hello world");
    </script>
</html>

If you try out all these 3 variations where the script tags are placed in different parts of the HTML, you'll see that the alert() call will still run; regardless of their position in the HTML document.

So I think the answer to your question is:

C. Both of the above

Since there is no choice that says "Anywhere within the html document"

Burning Crystals
  • 1,157
  • 3
  • 19
  • 35
  • I was thinking the same exact thing. I chose "C" as the answer. I saw that the "Script" could be place anywhere between the and as well as the and therefore, due to the wording of the question, I was thinking the best logical choice was "C" – jay165 Jun 27 '15 at 16:27
0

It is a good idea to place scripts at the bottom of the element. This can improve page load, because HTML display is not blocked by scripts loading.

You should prefer here:

DragonK
  • 59
  • 1
  • 9
0

I chose "C" both of the above because the "Script" can be placed anywhere between the and < / body> as well as the < head> and < / head> It appears the most logical answer to go with in this situation is "C"

jay165
  • 13
  • 4