Page 1 of 1

Variable reference, rather then replica.

Posted: Fri Jan 12, 2007 11:05 pm
by JellyFish
I'm looking for a way to define a javascript variable and have it equal the reference of another object, not just create a new object like it. E.g:

Code: Select all

Myvar = document.all? document.all["theID"] : document.getElementById? document.getElementById("theID") : "";
I'm not using var keyword 'cause I'm declaring it as global. But what I'm wanting here is that Myvar equals to the reference of all the elements that acquire the id, "theID", if possible. What I mean by reference is that if one or more elements are loaded with the id as "theID" then Myvar wouldn't need to reassign it's value, because it would just be a reference. So every time I write "Myvar.style.etc" it'd be just like writing "document.getElementById("theID").style.etc".

Is this possible in anyway?

Posted: Fri Jan 12, 2007 11:40 pm
by feyd
Objects are passed by reference in Javascript.

ID attributes must be unique in a document.

Posted: Sat Jan 13, 2007 12:05 am
by JellyFish
I don't understand. So, what you're saying is that if I write:

Code: Select all

Myvar = document.all? document.all["theID"] : document.getElementById? document.getElementById("theID") : "";
Then create a few more elements with the id "theID" then Myvar would uptade and include the new elements in it's selection?