Reputation: 6371
I'd like to get the document's width with javascript (jQuery available), which I could achieve simply with document.width
. The problem comes up when the contents are positioned with a negative value, because document.width
will retrieve the width less that value (you can see this behavior in http://jsfiddle.net/McgzK/1/). So, is there a way I can get the document's width straight forward, or should I do something like document.width - parseInt($(container).css('left'))
?
Upvotes: 1
Views: 609
Reputation: 57690
There is no straight forward way to get that width. This width does not make any sense. document.width
is the value of documents width. If you put something outside document layout its not included in documents width as its not in the document. So for your Total width you have to add that portion.
Use the scrollWidth property of your element and add absolute left
value of css position.
See http://jsfiddle.net/McgzK/11/
Note:
scrollWidth
property.offsetWidth
. Upvotes: 1
Reputation: 1109
Try setting your body width to 100% in your CSS, then use jQuery to get the width of the body rather than the document.
Upvotes: 0