Introduction to JavaScript
- Previous Page JS Tutorial
- Next Page JS Usage
This chapter provides some examples to demonstrate the capabilities of JavaScript.
JavaScript can change HTML content
getElementById()
It is one of multiple JavaScript HTML methods.
This example uses this method to "find" the HTML element with id="demo" and display its content (innerHTML
Change it to "Hello JavaScript":
Example
document.getElementById("demo").innerHTML = "Hello JavaScript";
Tip:JavaScript accepts both double quotes and single quotes:
Example
document.getElementById("demo").innerHTML = 'Hello JavaScript';
JavaScript can change HTML attributes
This example changes by changing <img>
of the src
Attribute (source) to change an HTML image:
Bulb

JavaScript can change HTML styles (CSS)
Changing the style of an HTML element is a variant of changing HTML attributes:
Example
document.getElementById("demo").style.fontSize = "25px";
JavaScript can hide HTML elements
Can be changed by display
Style to hide HTML elements:
Example
document.getElementById("demo").style.display="none";
JavaScript can display HTML elements
Can be changed by display
Style to display hidden HTML elements:
Example
document.getElementById("demo").style.display="block";
Supplementary Reading
Advanced JavaScript Tutorial: JavaScript History , JavaScript Implementation
- Previous Page JS Tutorial
- Next Page JS Usage