Sunday 15 September 2013

Confused by my attempt to use GetBoundingClientRect()

Confused by my attempt to use GetBoundingClientRect()

var rect = document.getElementById("object").getBoundingClientRect();
console.log("rect.top, rect.right, rect.bottom, rect.left");
<div id="object"></div>
.object {
background: red;
width: 20px;
height: 20px;
position: relative;
top: 200px;
}
Super elementary question... I am trying to get the coordinates of
#object, but the console returns rect.top, rect.right, rect.bottom,
rect.left instead of the actual coordinates of #object. What am I missing?
JSFiddle: http://jsfiddle.net/tCraA/2/

No comments:

Post a Comment