By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,384 Members | 1,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,384 IT Pros & Developers. It's quick & easy.

Div's top and left style properties yield NaN

P: n/a
I give up. I've been banging my head on the keyboard for the last
half-hour over this one. Can someone please point out what the heck I'm
doing wrong? I'm trying to move a block of text on screen. I have a div
element like this:

<div name="thetext" id="thetext" class="mtext">
blah blah blah
</div>

In the script to move the div, I try to retrieve the div's current
position. I do it this way:

obj = document.getElementById('thetext');
topPos = parseInt(obj.style.top);
leftPos = parseInt(obj.style.left);
I keep getting "NaN" for both topPos and leftPos. Can anyone tell me
why?

--Rick

Sep 28 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Rick wrote:
I give up. I've been banging my head on the keyboard for the last
half-hour over this one. Can someone please point out what the heck I'm
doing wrong? I'm trying to move a block of text on screen. I have a div
element like this:

<div name="thetext" id="thetext" class="mtext">
blah blah blah
</div>

In the script to move the div, I try to retrieve the div's current
position. I do it this way:

obj = document.getElementById('thetext');
topPos = parseInt(obj.style.top);
leftPos = parseInt(obj.style.left);
I keep getting "NaN" for both topPos and leftPos. Can anyone tell me
why?


Probably because they are undefined and parseInt() thinks 'undefined' is
not a number. Did you try -- alert(obj.style.left) -- ?

obj.style is a reference to obj's style object. You are accessing its
properties, but the code you posted does not set any of them, it just
sets the className to 'mtext'. If you want a solution:

<URL:http://www.quirksmode.org/js/findpos.html>


--
Rob
Sep 28 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.