JavaScript Remove Element
In this section, you will learn how to remove HTML element using JavaScript.
JavaScript provides several methods which allow the user to remove particular HTML element. Here we are going to remove a div element. For this purpose, we have created a div element. The method document.getElementById() grabs the element of specified id. Assign this element in the variable 'el'. Now in order to remove this element, we have used the variable 'el' with the JavaScript property parentNode that will returns a reference to the node's parent node and then refer to the JavaScript method removeChild() that will remove the specified element.
Here is the code:
| <html> <h2>Remove Element</h2> <script> function removeElement(){ var el = document.getElementById('id'); var remElement = (el.parentNode).removeChild(el); } </script> <input type="button" value="Remove Div" onclick="removeElement();" /><br><br> <div id="id" style="background-color:lightBlue;width:90;height:20;border:1px solid black">Hello World</div> </html> |
Output will be displayed as:
On clicking the button, the div element will get removed:

Tutorials
- Clear cookie example
- JavaScript getElementById innerHTML
- JavaScript getElementById Style
- Javascript Examples
- JavaScript add row dynamically to table
- New Page 1
- JavaScript Change link
- JavaScript Checkbox getElementById
- javascript clear textarea
- JavaScript Clock Timer
- JavaScript Cookies
- JavaScript Date Difference
- JavaScript duplicate string
- JavaScript Email Validation
- javascript focus input
- JavaScript get excel file data
- JavaScript getAttribute Href
- JavaScript getAttribute Style
- JavaScript getElementById div
- JavaScript getElementById Iframe
- JavaScript getElementById select
- JavaScript Hide Button
- JavaScript Hide Div
- JavaScript hide image
- JavaScript Hide Table Column
- JavaScript Hide Table Rows
- JavaScript Key Event
- JavaScript link
- JavaScript method location
- JavaScript move div
- JavaScript move file
- JavaScript move image
- JavaScript Navigate Back
- JavaScript navigate to page
- JavaScript Navigate to URL
- JavaScript indexOf substring
- JavaScript onkeypress event
- JavaScript Open file
- JavaScript Open link in new window
- JavaScript Open Modal Window


