how to get right offset of an element? - jQuery

Alex picture Alex · Jun 15, 2010 · Viewed 117.9k times · Source

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!!

Answer

Brendon Crawford picture Brendon Crawford · Jun 22, 2012

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 )