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?

AFK
  • 4,145
  • 4
  • 21
  • 22

1 Answers1

2

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.

Community
  • 1
  • 1
Nick Craver
  • 610,884
  • 134
  • 1,288
  • 1,151