[Javascript] Changing an Objects ID and Name

Peter Lauri lists at dwsasia.com
Thu Sep 7 02:58:00 CDT 2006


I thought it was the opposite so that something declared as var will be
"global". For example:

var thisVariable = 50;
thisNoVariable = 5;

trythis();

trythisno();

function trythis() {
	alert(thisVariable);
}

function trythisno() {
	alert(thisNoVariable);
}

I have not tested this, but I do believe there will be an error in the
function trythisno().

/Peter

-----Original Message-----
From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu]
On Behalf Of Jonathan Buchanan
Sent: Thursday, September 07, 2006 1:08 PM
To: [JavaScript List]
Subject: Re: [Javascript] Changing an Objects ID and Name

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.
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list