JavaScript is the world most popular programming language. JavaScript is the programming language of the Web. JavaScript is easy to learn.
JavaScript is one of the 3 languages all web developers must learn:
One of many JavaScript HTML methods is getElementById(). The example below finds an HTML element (with id="demo"), and changes the element content to "Hello JavaScript".
Changing the style of an HTML element is a variant of changing an HTML attribute.
<!DOCTYPE html>
<html>
<body>
<h2>What Can JavaScript Do?</h2>
<p id="demo">JavaScript can change HTML content.</p>
<button type="button"
onclick="document.getElementById('demo').innerHTML = 'Hello JavaScript!'">
Click Me!</button>
<br><br>
<p id="demo2">JavaScript can change style too!</p>
<button onclick="document.getElementById('demo2').style.color='red'">
Change Color</button>
</body>
</html>
Take our JavaScript Tutorial quiz and earn a certificate.