[Javascript] Changing an Objects ID and Name

Jonathan Buchanan jonathan.buchanan at gmail.com
Thu Sep 7 01:07:52 CDT 2006


On 9/7/06, Terry Riegel <riegel at clearimageonline.com> wrote:
>
> I modified it slightly to include the type of node being swapped.
>
> function swapNodes(n1, n2, k)
> {
>     var placeHolder = document.createElement(k);
>     n1.parentNode.replaceChild(placeHolder, n1);
>     n2.parentNode.replaceChild(n1, n2);
>     placeHolder.parentNode.replaceChild(n2, placeHolder);
> }
>
> Is there some type of cleanup needed to remove the temporary node
> (placeHolder)? Or is it local to the function and gets removed
> automatically?

As placeHolder is declared using "var", it's local to the function.
When the function returns, placeHolder is not attached to the document
any more and there are no other references to it hanging around, so it
should get removed automatically.

FWIW, the type of element used for the placeHolder doesn't really matter.

Jonathan.



More information about the Javascript mailing list