This is probably a really simple question, but how do I go about getting the right offset of an element in jQuery?
I can do:
$("#whatever").offset().left;
and it is valid.
But it seems that:
$("#whatever").offset().right
is undefined.
So how does one accomplish this in jQuery?
Thanks!!
jQuery offset() Method The offset() method set or returns the offset coordinates for the selected elements, relative to the document. When used to return the offset: This method returns the offset coordinates of the FIRST matched element. It returns an object with 2 properties; the top and left positions in pixels.
You can call the method getBoundingClientRect() on a reference to the element. Then you can examine the top , left , right and/or bottom properties... var offsets = document. getElementById('11a').
The jQuery offset() function is a built-in function in jQuery, by which we can return the offset of the bottom coordinate. The jQuery offset() function only specifies the top and left properties position, but with the help of top property and outerHeight() function, we can get the bottom position for elements.
Alex, Gary:
As requested, here is my comment posted as an answer:
var rt = ($(window).width() - ($whatever.offset().left + $whatever.outerWidth()));
Thanks for letting me know.
In pseudo code that can be expressed as:
The right offset is:
The window's width MINUS
( The element's left offset PLUS the element's outer width )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With