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!!
Just an addition to what Greg said:
This code will get the right position relative to the left side. If the intention was to get the right side position relative to the right (like when using the CSS
right
property) then an addition to the code is necessary as follows:This code is useful in animations where you have to set the right side as a fixed anchor when you can't initially set the
right
property in CSS.Actually these only work when the window isn't scrolled at all from the top left position.
You have to subtract the window scroll values to get an offset that's useful for repositioning elements so they stay on the page: