Possible Duplicate:
JavaScript: remove element by id
I only know their respective ids and don't know specifically about their parent nodes....
You can remove element by Id in javascript using the document.getelementbyid("element_id").remove() method. In this tutorial, you’ll learn how to remove elements by id using different methods and when appropriate to use those methods. Webpages are made up of DOM elements. According to DOM, every HTML tag is an object.
In this article, we will discuss three simple ways to remove a specific ‘div’ element using plain Javascript. Using parentNode.removeChild (): This method removes a specified child node from the DOM tree and returns the removed node. Example: This example uses the parentNode.removeChild () method to remove a specific ‘div’ element.
Hence we can remove a specified ‘div’ element by setting its contents to “” using the outerHTML property. Example: This example uses the outerHTML attribute to remove a specific ‘div’ element. Using .remove (): This method removes the specified div element and all its child nodes.
ID is the property used to identify the web page elements, and each element has a unique id across the document. Get the element by using its ID and invoke the remove() method in that element.
You can use parentNode
on the element to get its parent, and use removeChild
on it.
var el = document.getElementById( 'id' );
el.parentNode.removeChild( el );
In jQuery, just $('#your_id').remove();
will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With