Variable reference, rather then replica.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Variable reference, rather then replica.

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Objects are passed by reference in Javascript.

ID attributes must be unique in a document.
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post 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?
Post Reply