How to get a notification when an element is added to the page using JavaScript? Last Updated : 24 Jun, 2024 Comments Improve Suggest changes Like Article Like Report To show a notification when an element is added to the page we can use the to createElement() method to create an element list with the specified name. Detect element addition dynamically in the DOM using JavaScript. Trigger an alert to notify users upon appending new elements to the page. ApproachThe JavaScript function add() is defined to handle the process of adding an <li> element to the DOM when invoked by clicking a button.Inside the function, a new <li> element is dynamically created using document.createElement("li").A text node containing the string "JS" is created using document.createTextNode("JS").The text node is appended as a child of the <li> element, and then the <li> element is appended to an existing <ul> list with the id "myList". After the element is appended, an alert message is triggered using an alert("Element is getting added"), notifying the user that an element has been added to the page.Example: The example below shows the above-explained approach. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>button to append an item to the end of the list</title> </head> <body> <b> Click the button to append an item to the end of the list. </b> <ul id="myList"> <li>HTML</li> <li>CSS</li> </ul> <br> <button onclick="add()"> Add Elements </button> <script> function add() { // Add li element let node = document .createElement("li"); // Add element into the list let textnode = document .createTextNode("JS"); // Append the element into the list node.appendChild(textnode); document.getElementById("myList") .appendChild(node); // Alert message when element gets added alert("Element is getting added"); } </script> </body> </html> Output:Â Comment More infoAdvertise with us Next Article How to get a notification when an element is added to the page using JavaScript? romy421kumari Follow Improve Article Tags : JavaScript Web Technologies HTML-Misc HTML-Questions Similar Reads How to append data to <div> element using JavaScript ? To append the data to <div> element we have to use DOM(Document Object Model) manipulation techniques. The approach is to create a empty <div> with an id inside the HTML skeleton. Then that id will be used to fetch that <div> and then we will manipulate the inner text of that div. 1 min read How to run a function when the page is loaded in JavaScript ? A function can be executed when the page loads successfully. This can be used for various purposes like checking for cookies or setting the correct version of the page depending on the user's browser. Below are the approaches to run a function when the page is loaded in JavaScript: Table of Content 2 min read How to make a Toast Notification in HTML CSS and JavaScript ? A Toast Notification is a small, non-intrusive popup message that briefly appears on the screen to provide feedback or updates. It features 4 distinct toast types triggered by buttons: "Submit" for a green "Success" toast, each with unique CSS animations. JavaScript manages their display duration. T 4 min read How to detect If textbox content has changed using JavaScript ? Detecting if the content of a textbox has changed in JavaScript means identifying when a user modifies the text within an input field. This can be achieved using events like input, change, or keyup, which trigger JavaScript functions in response to content alterations.There are some common approache 3 min read How to use the alert() method in JavaScript ? In this article, we will learn how to use the alert() method in JavaScript. The alert() method is used to show an alert box on the browser window with some message or warning. We can use it as a message or as a warning for the user. Approach: To show an alert on the browser window, we make a button. 2 min read Like