Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get right position of Element?

Tags:

I wish to get the right position of an element. I have tried attr('right') and I have read the API document regarding .position().right which is non existent (I believe).

http://jsfiddle.net/xavi3r/vcuq7/

Is an example I wish to alert the right value for.

like image 806
Xavier Avatar asked Aug 17 '11 09:08

Xavier


People also ask

How do you position an element to the right?

If position: absolute; or position: fixed; - the right property sets the right edge of an element to a unit to the right of the right edge of its nearest positioned ancestor. If position: relative; - the right property sets the right edge of an element to a unit to the left/right of its normal position.

How do you get the position element XY?

The position of (X, Y) means the co-ordinate of an element at the top-left point in a document. X represent the horizontal position and Y represent the vertical position. Use element. getBoundingClientRect() property to get the position of an element.

How do you right an element in HTML?

You can use two values top and left along with the position property to move an HTML element anywhere in the HTML document. Move Left - Use a negative value for left. Move Right - Use a positive value for left. Move Up - Use a negative value for top.

How do you find the absolute position of an element?

top , or offsetLeft , offsetTop can be used to get (or set) the position of an element within its parent. So, to get the element's absolute position within the document, we should move upwards on the element's tree and add the position of all the element's parents (except the latest document element).


2 Answers

You want to find the value of the CSS right property?

$('#foo').css('right'); 

In plain Javascript:

document.getElementById('foo').style.right; 

But, if you want to find the calculated distance from the right edge of an element to the right edge of another one, then you'll have to do that yourself, combining .position().left and .offsetWidth

like image 129
nickf Avatar answered Nov 03 '22 00:11

nickf


It looks to me that this works:

jQuery('#elem').offset().left + jQuery('#elem').width()  

Fiddle: http://jsfiddle.net/adamovic/fcyL5sg0/

like image 37
Mladen Adamovic Avatar answered Nov 02 '22 23:11

Mladen Adamovic