var newDiv = document.createElement("div");
Once you have created an HTML element, you can add it to the page using the appendChild() method. For example, the following code adds the new div element to the body of the page:
document.getElementById("myElement").innerHTML = "New content";
document.getElementById("myImg").src = "new-image.jpg";
Step 1: Create a new file
The first step is to create a new file. You can use any text editor, such as Notepad, Sublime, or Visual Studio Code. Open your text editor and create a new file by clicking on “File” and then “New”.
Step 2: Save the file
The next step is to save your file. Click on “File” and then “Save As”. Give your file a name and make sure to add the .js extension at the end of the file name. For example, you could name your file “script.js”.
<script> at the beginning of your file and
For example, you could add the following code:
<script> alert("Hello, world!"); </script>
This code will display an alert box on the screen with the message “Hello, world!”.