tags:

views:

60

answers:

1

In javascript I have a problem with a script I am writing. I need to be able to get the starting top and left positions of an html object like a table or an image that are defined in the CSS.

When I define the left(20px) and top(20px) offsets for the table I run the javascript console built into chrome and do parseInt(document.getElementById('component1').style.left) to see if it will give me the magnitude of the offset as a number. However, it returns NaN. I'm guessing because the browser isn't initializing these values(I thought setting it explicitly in the CSS, that the browser would)

Any ideas as to how I can get around this?

+1  A: 

Is jQuery an option? If so:

var offset = $("#component1").offset;
//use offset.left, offset.top for whatever you need

If not, you can do this by looping, see this answer.

Nick Craver
the looping answer didn't work :\ I will see about getting jQuery.
AFK
got jquery .offset.left and .offset.top are undefined.
AFK
found the answer in the thread you linked.
AFK