0

from this topic: How can I position an element next to user text selection?

i can get the left position from:

 var obj = arrow_btn;
            var left = top = 0;
            do {
                left += obj.offsetLeft;
                top += obj.offsetTop;
            } while (obj = obj.offsetParent);

            console.log("left="+left);
            console.log("top=" + top);

but I get in the console: left=590 top=[object DOMWindow]

any comments on why I can't get the Top?

Community
  • 1
  • 1
blic
  • 103
  • 1
  • 9

1 Answers1

1

Yes, "top" is an immutable property of the global object "window" that refers to the top frame (DOMWindow). Your code is equivalent to:

var left;
window.top = 0; // no effect
left = window.top;
....

To correct it, just make sure top is a var;

var left = 0,
    top = 0;
12000
  • 103
  • 2