JavaScript Introduction

JavaScript is a lightweight, cross-platform, and interpreted scripting language. It is well-known for the development of web pages, many non-browser environments also use it. JavaScript can be used for Client-side developments as well as Server-side developments.

One of many JavaScript HTML methods is getElementById()

The example below “finds” an HTML element (with id=”demo”), and changes the element content (innerHTML) to “Hello JavaScript”:

Copy the below HTML code into Notepad:

<!DOCTYPE html>
<html>
<body>

<h2>Example of JavaScript</h2>

<p id="test">JavaScript can change HTML content.</p>

<button type="button" onclick="document.getElementById('test').innerHTML = 'Hello World!'"> Click Me </button>

</body>
</html>

Final output will show following result:

Example of JavaScript

JavaScript can change HTML content.

Leave a Reply

Your email address will not be published. Required fields are marked *