Shopping cart

Subtotal:

$78.00

JavaScript Where To

JavaScript Where To



[/code]
Old JavaScript examples may use a type attribute: [snippet]

Demo JavaScript in Head

A Paragraph

[/code]


JavaScript in [snippet][/snippet]


In this example, a JavaScript is placed in the [snippet][/snippet] section of an HTML page.

The function is invoked (called) when a button is clicked:

Example

[code]

Demo JavaScript in Body

A Paragraph

[/code]

Placing scripts at the bottom of the [snippet][/snippet] element improves the display speed, because script interpretation slows down the display.


External JavaScript


Scripts can also be placed in external files:

External file: myScript.js

[code] function myFunction() { document.getElementById("demo").innerHTML = "Paragraph changed."; } [/code]

External scripts are practical when the same code is used in many different web pages.

JavaScript files have the file extension .js.

To use an external script, put the name of the script file in the src (source) attribute of a script tag:

Example

[code] [/code]

You can place an external script reference in [snippet][/snippet] or [snippet][/snippet] as you like.

The script will behave as if it was located exactly where the [snippet] [/code]


External References


With a full URL (a full web address)

With a file path (like /js/)

Without any path


This example uses a full URL to link to myScript.js:


Example

[code] [/code]

This example uses a file path to link to myScript.js:


Example

[code] [/code]

This example uses no path to link to myScript.js:


Example

[code] [/code]

You can read more about file paths in the chapter HTML File Paths.
`; const decoded = html_data .replace(/"/g, '"') .replace(/'/g, "'") .replace(/</g, "<") .replace(/>/g, ">") .replace(/&/g, "&"); container.innerHTML = renderHTML(decoded); });