JavaScript Placement
JavaScript can be placed in the and the sections of an HTML page.
The tags.
Example
document.getElementById("demo").innerHTML = "My First JavaScript";
Older examples may use a type attribute:
My Web Page
A Paragraph
JavaScript in
In this example, a JavaScript function is placed in the section of an HTML page.
The function is invoked (called) when a button is clicked:
Example
My Web Page
A Paragraph
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph changed.";
}
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.External JavaScript
Scripts can also be placed in external files.
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 the
You can place an external script reference in or as you like.
The script will behave as if it was located exactly where the
تعليقات
إرسال تعليق