Reputation: 2337
how to get the right position of an element?
I can get the left and top position but can't figure out how to get the right position using jquery position() method
var ul_list_position = $("#list");
var ul_list_left_positon_value = ul_list_position.position();
alert("Left position: "+ ul_list_left_position_value.left);
Upvotes: 0
Views: 8541
Reputation: 4575
To get the right position you have to know the width of the container as well. So rather than just adding the width of the element to the left position, you need to also take that value away from the container width. For example:
var right = $container.width() - ( $element.position().left + $element.width() )
Hope that helps :)
Upvotes: 9
Reputation: 9027
var left = $("#list").position().left; // get left position
var width = $("#list").width(); // get width;
var right = width + left; // add the two together
Upvotes: 3