Jump to content
patricia_grace

Script tag needed...?

Recommended Posts

In the beginning of the JavaScript tutorial, there are several examples of working with JavaScript that don't include any script tags. I was able to duplicate the examples with my own text editor and browser, also.

 

However, later in the tutorial it is stated "In HTML, JavaScript code must be inserted between <script> and </script> tags."

 

It is a bit confusing, and I am wondering why the script tags weren't needed in the first few examples, such as the one below:

 

<!DOCTYPE html>
<html>
<body>
<h1>What Can JavaScript Do?</h1>
<p id="demo">JavaScript can change HTML content.</p>
<button type="button" onclick="document.getElementById('demo').innerHTML = 'Hello JavaScript!'">Click Me!</button>
</body>
</html>
Which runs fine without the script tags. I was able to duplicate it with my own text editor and browser.
Thanks in advance for any help offered!
patricia

Share this post


Link to post
Share on other sites

In Fact,You Can Run JavaScript In Several Ways,You Can Create A Script Directly In Your Page Or Embed It From External Source Using The <script> Tag,Or You Can Add It Inline Using Events Like "onclick",So Actually There Is No Difference.

  • Like 1

Share this post


Link to post
Share on other sites

They are wrong when they say it must be embedded in <script> tags. It also can be in an even attribute.

 

But as a general rule, you use <script> tags for Javascript. I discourage the use of event attributes.

  • Like 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...