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’; |
Altering the style of an HTML element represents a variation of modifying an HTML attribute.
Example
document.getElementById(“demo”).style.fontSize = “35px”; |
Concealing HTML elements is achievable by adjusting the display style.
Example
document.getElementById(“demo”).style.display = “none”; |
Revealing previously hidden HTML elements can also be accomplished by adjusting the display style.
Example
document.getElementById(“demo”).style.display = “block”; |