Hello! Tell me, please, how to use jQuery to determine the position of an element on a page?

The task is as follows: there is a div parent, and the parent element should have a class added if the parent is close to the right edge of the browser window.

Thanks in advance for your help!

    1 answer 1

    .offset() - for example

     var element = $("#mydiv"); var offset = element.offset(); element.html( "left: " + offset.left + ", top: " + offset.top ); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="mydiv"></div>