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.
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.
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.
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.
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).
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
It looks to me that this works:
jQuery('#elem').offset().left + jQuery('#elem').width()
Fiddle: http://jsfiddle.net/adamovic/fcyL5sg0/
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