JavaScript/JavaScript within HTML: Difference between revisions
[checked revision] | [checked revision] |
Content deleted Content added
No edit summary |
update to HTML5 |
||
Line 4:
All JavaScript, when placed in an HTML document, needs to be within a {{HTML:element|script}} element. A {{HTML:element|script}} element is used to link to an external JavaScript file, or to contain inline scripting (script snippets in the HTML file). A {{HTML:element|script}} element to link to an external JavaScript file looks like:
<source lang=
<script
</source>
while a {{HTML:element|script}} element that contains inline JavaScript looks like:
<source lang=
<script
// JavaScript code here
</script>
Line 23:
Using inline JavaScript allows you to easily work with HTML and JavaScript within the same page. This is commonly used for temporarily testing out some ideas, and in situations where the script code is specific to that one page.
<source lang=
<script type="text/javascript">
// JavaScript code here
|