[Javascript] Changing an Objects ID and Name

Jonathan Buchanan jonathan.buchanan at gmail.com
Thu Sep 7 06:10:57 CDT 2006


On 9/7/06, Paul Novitski <paul at juniperwebcraft.com> wrote:
> Jonathan, I suspect you're wrong on this point.  While I agree that
> the variable 'placeHolder' is local to the function 'swapNodes()' and
> will be cleared when the function terminates, surely when you invoke
> the DOM method createElement() you're creating a new element IN THE
> DOM which has got to be about as global as you can get in a script
> running in the context of the Document Object Model.
>
> Am I wrong about this?  Does the createElement() method return a node
> object that isn't actually part of the DOM and doesn't persist when
> the calling function returns?
>
> Regards,
> Paul

Correct - the element returned from the createElement function isn't
actually in the document's DOM tree until you insert it. The element
holds a reference to its ownerDocument, but the ownerDocument doesn't
hold a reference to the element. The situation is the same after the
element has been inserted and then removed from the DOM tree. So when
the function terminates, placeHolder is a locally scoped variable to
which there are no references.

Jonathan.



More information about the Javascript mailing list