Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS Introduction

JavaScript Can Change HTML Content

One of JavaScript’s HTML methods, getElementById(), is utilized in the following example to locate an HTML element identified by the ID “demo”. Subsequently, it alters the content of the element (innerHTML) to display “Hello JavaScript”.

Example

document.getElementById(“demo”).innerHTML = “Hello JavaScript”;
JavaScript allows the use of both double and single quotes interchangeably.

Example

document.getElementById(‘demo’).innerHTML = ‘Hello JavaScript’;

JavaScript Can Change HTML Styles (CSS)

Altering the style of an HTML element represents a variation of modifying an HTML attribute.

Example

document.getElementById(“demo”).style.fontSize = “35px”;

JavaScript Can Hide HTML Elements

Concealing HTML elements is achievable by adjusting the display style.

Example

document.getElementById(“demo”).style.display = “none”;

JavaScript Can Show HTML Elements

Revealing previously hidden HTML elements can also be accomplished by adjusting the display style.

Example

document.getElementById(“demo”).style.display = “block”;