How to Create a Simple JavaScript Web Page?

Estimated read time 1 min read

Here is an example to create a simple JavaScript web page:

<!DOCTYPE html>
    <title>My Simple JavaScript Web Page</title>
    <h1 id="title">My Simple JavaScript Web Page</h1>
    <p>Click the button below to change the text of the title:</p>
    <button id="myButton">Click Me</button>
      var title = document.getElementById("title");
      var button = document.getElementById("myButton");

      button.addEventListener("click", function() {
        title.innerHTML = "The text has been changed";

This code creates a simple HTML page with a heading and a button. When the button is clicked, the text of the heading is changed using JavaScript. The JavaScript code uses the document.getElementById method to select the heading and button elements, and the addEventListener method to attach a click event listener to the button. The event listener updates the text of the heading using the innerHTML property.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply