
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
JavaScript program to update DOM
Following is the code to update DOM in JavaScript −
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 20px; font-weight: 500; color: rebeccapurple; } </style> </head> <body> <h1>Update DOM JavaScript</h1> <div style="color: green;" class="result"></div> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to create a new element</h3> <script> let resEle = document.querySelector(".result"); let heading = document.createElement("h3"); document.querySelector(".Btn").addEventListener("click", () => { let headingText = document.createTextNode("This is a random heading"); heading.appendChild(headingText); resEle.appendChild(heading); }); </script> </body> </html>
Output
The above code will produce the following output −
On clicking the ‘CLICK HERE’ button −
- Related Articles
- Update array of objects with JavaScript?
- Java Program to Update value of HashMap using key
- C++ Program to Update value of Dictionary using key
- Swift Program to Update value of Dictionary using key
- Incrementing a date in JavaScript, in order to update MongoDB?
- Program to update elements in a given range in Python
- What are JavaScript DOM Events?
- How to add rows to a table using JavaScript DOM?
- How to add a class to DOM element in JavaScript?
- Search and update array based on key JavaScript
- JavaScript Update specific index in a boolean matrix?
- How to create a table caption with JavaScript DOM?
- Golang Program to update the node value after the Kth node.
- Program to update list items by their absolute values in Python
- How to style background image to no repeat with JavaScript DOM?

Advertisements