HTML JavaScript

JavaScript makes HTML pages more dynamic and interactive.

The HTML <script> Tag

HTML <script> tag is used to define a client side script (JavaScript).

The <script> element contains text statements, or identifies an external text file with the src attribute.

Common uses of JavaScript are image manipulation, form verification, and dynamic content changes.

To select an HTML object, JavaScript usually uses the document.getElementById() method.

This JavaScript example is labeled "Hello JavaScript!" in an HTML object with id = "demo":


Example
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>

A Taste of JavaScript

Here are some examples of what JavaScript can do:

Example

JavaScript can change styles:

document.getElementById("demo").style.fontSize = "25px";
document.getElementById("demo").style.color = "red";
document.getElementById("demo").style.backgroundColor = "yellow";