/    Sign up×
Community /Pin to ProfileBookmark

accessing an object as variable

Im trying to move an image within an iframe. The problem is that I have the id of the iframe in a variable and I cant get it to work.

This works great:
Games.document.all[‘DivBorderTR’].style.left = 100;

But this doesnt:
$module = ‘Games’;
getElementById( $module ).document.all[‘DivBorderTR’].style.left = 100;

(I have several iframes that looks similar and this code is supposed to work for any iframe-id given in $module.)

You can look at it at: [url]www.battlesite.com/henrik/battlesite2[/url] (just press login-button – no userid or password required)

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisNov 05.2003 — A JavaScript identifier, or name, must start with a letter or underscore ("_"); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase).[/quote]
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/guide/ident.html#1008333
Copy linkTweet thisAlerts:
@shumwayauthorNov 05.2003 — Thanks for your answer gil davis but im not sure I follow you. The id "Games" do follow the rules and variables starts with $-signs dont they - at least everything else works fine with that.
Copy linkTweet thisAlerts:
@Khalid_AliNov 05.2003 — Actually you can use $sign to begin a variable name.

I think in your code you are not using document before getEle,,,,

getElementById( $module )

should be

document.getElementById( $module )

and instead of using document.all[] use document.getElementById
×

Success!

Help @shumway spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...