/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] DIV is Null???

I am trying to change the style “left” on a div. For some reason I keep getting the error that div is null.. Can’t figure out how I screwed up..

[code=php]<script language=”JavaScript” type=”text/javascript”>
function centerIt() {
if (self.innerHeight)
{
var x = self.innerWidth;
}
else if (document.documentElement && document.documentElement.clientHeight)
{
var x = document.documentElement.clientWidth;
}
else if (document.body)
{
var x = document.body.clientWidth;
}
var w_box = x;
var w_total = (w_box – 760)/2;
var div = document.getElementById(“container”);
div.style.left = w_total +”px”;
}
centerIt();
</script>
<div id=”container” style=”width: 760px; height: 75px; background-color: #FFFFFF; position: absolute; top: 0px; left: 0px;”>
Top Menu Bar
</div>
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@cluefulJul 02.2011 — [I]At the point that the div is referenced[/I], it does not exist. I'm sure you see why.
Copy linkTweet thisAlerts:
@fotofxauthorJul 02.2011 — Yup... It hit me just as you were answering.. I need to do an onload or jquery document ready..
Copy linkTweet thisAlerts:
@cluefulJul 03.2011 — Yup... It hit me just as you were answering.. I need to do an onload or jquery document ready..[/QUOTE]Or just call the function in a script block anywhere below the div.
Copy linkTweet thisAlerts:
@fotofxauthorJul 03.2011 — Thanks again..
×

Success!

Help @fotofx 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.27,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

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