JavaScript is the programming language of the Web.
All modern HTML pages are using JavaScript.
JavaScript Can Change HTML Content
One of many HTML methods is document.getElementById().
This example "finds" the HTML element with id="demo", and changes its content (innerHTML):
All modern HTML pages are using JavaScript.
JavaScript Can Change HTML Content
One of many HTML methods is document.getElementById().
This example "finds" the HTML element with id="demo", and changes its content (innerHTML):
Example
document.getElementById("demo").innerHTML = "Hello JavaScript";
JavaScript Can Change HTML Styles (CSS)
Changing the style of an HTML element, is a variant of changing an HTML attribute:Example
document.getElementById("demo").style.fontSize = "25px";
JavaScript can be placed in the <body> and the <head> sections of
an HTML page.
The <script> Tag
In HTML, JavaScript code must be inserted between <script> and </script> tags.Example
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
For example, a function can be executed when an event occurs, like when the user clicks a button.
You will learn much more about functions and events in later chapters.
Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both.
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 <script> tag:
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
JavaScript Functions and Events
A JavaScript function is a block of JavaScript code, that can be executed when "asked" for.For example, a function can be executed when an event occurs, like when the user clicks a button.
You will learn much more about functions and events in later chapters.
JavaScript in <head> or <body>
You can place any number of scripts in an HTML document.Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in both.
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 <script> tag:
No comments:
Post a Comment