/    Sign up×
Community /Pin to ProfileBookmark

problem in getting an element

hello

I am getting “div” element by this way and assign a value.

document.getElementById(‘div’).style.left=xx

But it is null

what are the possible problem ?

regards

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMayFeb 27.2009 — #1 div is a reserved word and therefore shouldn't be used as an ID

#2 If you are setting ....left to anything other than zero you need to include the unit (px, em, etc).
Copy linkTweet thisAlerts:
@skywalker2208Feb 27.2009 — What does your html code look like because I am assuming that div is just the div html tag? If you want to target a specific div with the getElementById method then you need to give your div an id like [code=php]<div id="mydivid">[/code]. The getElementById on targets the id on the html elements, not the html element itself.
×

Success!

Help @orkun 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 5.6,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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