patricia_grace Posted September 15, 2016 Share Posted September 15, 2016 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 Link to comment Share on other sites More sharing options...
Eyad Syria-lover Posted September 15, 2016 Share Posted September 15, 2016 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. 1 Link to comment Share on other sites More sharing options...
Ingolme Posted September 15, 2016 Share Posted September 15, 2016 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. 1 Link to comment Share on other sites More sharing options...
dsonesuk Posted September 15, 2016 Share Posted September 15, 2016 What about an odd attribute? Can it be used with them also. :-) Link to comment Share on other sites More sharing options...
patricia_grace Posted September 15, 2016 Author Share Posted September 15, 2016 Perfect, thanks so much. It's reassuring to have confirmation! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now