faqts : Computers : Programming : Languages : JavaScript : Language Core : Objects

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 14 people (86%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

"delete MyObject" doesn't seem to properly delete the object?

Nov 14th, 2002 03:59
Mark Filipak, neko noguchi,


The answer depends upon where the object is 'located'. If it's an
ordinary javascript object (a property of the global object) created
like this:
  myObject = new Object();
or some other assignment type of statement, then delete myObject should
work.
But if it is a child node in the document tree, created like this:
  myObject = document.createDocumentFragment();
  void myObject.appendChild(document.createElement('DIV'));
or some other 'create' method of document, then you should use
removeChild to 'delete' it, like this:
  void document.removeChild(myObject.firstChild);
which deletes the DIV (and all of its children, if any), or
  myOldDiv = document.removeChild(myObject.firstChild);
which removes the DIV (and all of its children, if any) and saves it as
myOldDiv.
Ciao -- Mark Filipak