Home
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function () { $("button").click(function () { //get left offset var left = $('#mydiv').offset().left; //get right offset var top = $('#mydiv').offset().top; alert(left + ',' + top); //set new offset $('#mydiv').offset({ left: 60, top: 60 }); }); }); </script> </head> <body> <h1>jQuery Manipulation Methods: offset()</h1> <div id="mydiv" style="background-color: aquamarine;"> This is div </div> <button>Click Here to Test .offset()</button> </body> </html>
Result: