How can I determine the distance of an object to the right browser window border

Nicole Loyal Windham picture Nicole Loyal Windham · Mar 20, 2012 · Viewed 11.6k times · Source

How can I possibly figure out the distance from an object (div) to the right browser window border?

http://www.screencast.com/t/ryNgwa4E

Thanks!

Answer

danblundell picture danblundell · Mar 20, 2012
$(window).width() - ($('#your-element').offset().left + $('#your-element').width());

That takes the width of your element adds it to the position of the element within the document and takes it away from the whole window size which should leave you with the right hand distance between element and window.