Skip to content
Related Articles
Open in App
Not now

Related Articles

How to get a notification when an element is added to the page using JavaScript ?

Improve Article
Save Article
  • Last Updated : 12 May, 2021
Improve Article
Save Article

To show a notification when an element is added to page we can use createElement() method creates an element list with the specified name. After that, we will create a text node by createTextNode() method.Then we will append the new element in that list and use the alert() function to show a notification to the user. 

Below example illustrate the approach:

Example: In this example, we already have a list so we want another element in that list, but when we want to add an element in that list, we will show a notification alert when we click the button to add an element in that list.


<!DOCTYPE html>
            function add() {
                // Add li element
                var node = document
                // Add element into the list
                var textnode = document
                // Append the element into the list
                // Alert message when element gets added
                alert("Element is getting added") ;    
            <h1 style="color: green;">
                Click the button to append an item
                to the end of the list.
            <ul id="myList">
            <button onclick="add()">
                Add Elements


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!