JSFiddle - React, Tailwind, and code Playground

by Addy Osmani

HTML

<!DOCTYPE HTML>
<html>
  <head>
    <title>test offset of jquery</title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
  </head>
  <body>
    <div id="test">
      test offset of jquery
    </div>
  </body>
</html>

CSS

#test {
    margin: 100px;
    position: absolute;
}

JavaScript

var test = $('#test'),
    offset = test.offset(),
    left = offset.left,
    top1 = offset.top;
alert('top: ' + top1 + ', left: ' + left);
test.offset({top: top1, left: left});
offset = test.offset();
left = offset.left;
top1 = offset.top;
alert('top: ' + top1 + ', left: ' + left);