Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get right offset of an element? - jQuery

Tags:

jquery

offset

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

like image 707
Alex Avatar asked Jun 15 '10 06:06

Alex


People also ask

What is offset () in jQuery?

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.

How do you get the offset of a div?

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').

How do I get Offsetbottom?

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.


1 Answers

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 )

like image 166
Brendon Crawford Avatar answered Oct 13 '22 17:10

Brendon Crawford