Search code examples
javascriptremovechild

JavaScript removeChild not working


I am using this JavaScript code to remove a couple elements from the page, but it's not working. When I inspect the code with Opera Dragonfly it says something like:

Uncaught exception: Error: WRONG_ARGUMENTS_ERR

and points to the file and function name.

The weird thing is that I use the exact same code in another function on the same page and it works without problem. The code is very small and simple:

var docBody = document.getElementById("body");
if(document.getElementById("marginDiv")){
  docBody.removeChild("marginDiv");
}

Both body and marginDiv exist on the page. My goal is to make the thumbnails disappear when one clicks the background.


Solution

  • Try

    docBody.removeChild(document.getElementById("marginDiv"));