Questions tagged [removechild]

removes and returns a child node from the DOM

Description

Removes and returns a child node from the DOM.

The removed child node still exists in memory, but is no longer part of the DOM. It can still be re-used, via the oldChild object reference.

Syntax

var oldChild = element.removeChild(child);
element.removeChild(child);

where,

child is the child node to be removed from the DOM.

element is the parent node of child.

oldChild holds a reference to the removed child node. oldChild === child.

References

628 questions
43
votes
7 answers

Remove dom element without knowing its parent?

Is it possible to remove a dom element that has no parent other than the body tag? I know this would be easy with a framework like jquery, but I'm trying to stick to straight javascript. Here's the code I've found to do it otherwise: function…
Matrym
  • 15,021
  • 33
  • 90
  • 137
28
votes
4 answers

java.util.ConcurrentModificationException with iterator

I know if would be trying to remove from collection looping through it with the simple loop I will be getting this exception: java.util.ConcurrentModificationException. But I am using Iterator and it still generates me this exception. Any idea why…
user2219247
  • 1,213
  • 10
  • 19
  • 25
22
votes
5 answers

javascript remove li without removing ul?

Is there any way to remove the li elements of a ul without also removing the ul? I can only seem to find this. var element = document.getElementById('myList'); element.parentNode.removeChild(element); But, this removes the ul. I'm hoping to be able…
MAZUMA
  • 713
  • 3
  • 8
  • 20
18
votes
4 answers

Why can I not remove a child element I've just found? NOT_FOUND_ERR

I'm building a script which has to patch XML files, including replacing one list of elements with another. The following function applies a patch (involving a possibly empty list of elements with the same name) onto a parent Element's list of…
dhardy
  • 8,246
  • 5
  • 32
  • 41
16
votes
3 answers

Remove an element from the DOM from reference to element only

This is either very simple or impossible. I know I can do this: var element = document.getElementById('some_element'); element.parentNode.removeChild(element); ...but it feels messy. Is there a tidier - and universally supported - way to do the…
DaveRandom
  • 84,004
  • 11
  • 142
  • 168
13
votes
2 answers

Why does removeChild need a parent node?

After answering this question I am left wondering why removeChild needs a parent element. After all, we could simply do node.parentNode.removeChild(node); As the parent node should be always directly available to the Javascript/DOM engine, it is…
Marcel Korpel
  • 20,899
  • 5
  • 58
  • 79
11
votes
4 answers

Does removeChild really delete the element?

Does removeChild function really delete the child node completely? Or it just removes the element being child of the specified parant node? If it doesn't really deletes the element, is there a way to delete the element completely?
Yunus Eren Güzel
  • 2,699
  • 9
  • 34
  • 58
11
votes
2 answers

Error with getElementById(id).remove() in IE11

I have this code: document.getElementById(id).remove(); But, IE give me an error with this function. Do you know an other way for make this remove?
Manu
  • 642
  • 2
  • 9
  • 22
10
votes
4 answers

Creating an element that can remove it self?

I'm building a lightbox as a school project, and I can't use jQuery. I've got an image. When you click it, Javascript makes a transparent div with the ID "overlay". I want the div to remove itself, or the parent to remove it but it doesn't work. I…
Sam
  • 113
  • 1
  • 1
  • 4
8
votes
2 answers

removeChild() : how to remove indent too?

Let's consider the following XML document: item1 item2 Now, let's remove all the items and add some new item. Code: //-- assume we have Element instance of element: items_parent // and…
Dmitry Frank
  • 9,453
  • 7
  • 55
  • 101
8
votes
3 answers

Removing an element through the parentNode.removeChild throws a DOM Exception 8

I have code which is roughly as follows (I removed some parts, as they are irrelevant): Library.focus = function(event) { var element, paragraph; element = event.srcElement; paragraph = document.createElement("p"); …
user697108
  • 3,141
  • 3
  • 18
  • 14
7
votes
1 answer

Does removing a script element remove its functions from memory?

var scripts = document.getElementsByTagName("script"); for (var i=scripts.length; i--; ){ (scripts[i]).parentNode.removeChild(scripts[i]); } Someone asked me this question and my first thought was: no. However, when you remove the style…
vol7ron
  • 35,981
  • 19
  • 104
  • 164
6
votes
2 answers

How do you undo "surroundContents" in javascript?

I'm writing a script that needs to move a wrapping node element around on the page. I find that when I do this, I remove the previously wrapped children. How do I unnest the children of a node, so that I can move that parent node elsewhere? I was…
Matrym
  • 15,021
  • 33
  • 90
  • 137
5
votes
1 answer

How to trigger onunload event when removing iframe ?

How can the iframe's unload event be triggered when removing it? Using the code below, when removeChild(iframe) is called, the onunload event is not triggered. remove iframe
consatan
  • 219
  • 1
  • 6
  • 18
5
votes
2 answers

Android: How do I remove an item from a gridview, having the remaing items shuffle into place

BACKGROUND: I have a grid of 36 buttons, lets say a 6 rows & 6 columns numbered 1 to 36, displayed 2 rows at a time via a GridView and custom Adapter The grid displays fine, and all of the scrolling works properly. QUESTION: I want to be able to…
Noah
  • 14,450
  • 11
  • 98
  • 147
1
2 3
41 42