Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the overflowed width of an element in a webpage

I have two divs like so

<div id="parent" style="width:100px:overflow:hidden;">
    <div id="child"> 
      tooooooooooooooooooooo much content to fit in parent
    </div>
</div>

I'm dynamically updating the content of child and scrolling it using jQuery. I would like to be able to find how wide the child is so I know when to stop scrolling. The problem is that the child's actual width once the overflowed content is present, is wider than even the screen (seems to be about 2500 pixels with the current test content). The border of the element, if its set, does not extend to the actual width of the content, the text overflows beyond the visible border.

Using jQuerys $('#child').width , the clientWidth, scrollWidth (thanks bobince) and offsetWidth properties all max out at 1024px (which is the width of my monitor). Does any one know of any way to find out how wide the elements content is including the overflow? If it helps, The app I am building will run in a kiosk type environment, so a Firefox only (even a nightly version) solution is fine.

Update: scrollWidth on the parent works, I should have read more carefully, thank you again bobince.

like image 712
Sean O Donnell Avatar asked Apr 19 '09 01:04

Sean O Donnell


2 Answers

document.getElementById('parent').scrollWidth

scrollWidth is an IE extension that historically was less well supported than offsetWidth. However nowadays all the modern desktop browsers include it.

like image 67
bobince Avatar answered Oct 30 '22 11:10

bobince


Using JQuery, you can do:

$('#parent')[0].scrollWidth
like image 43
JoeTidee Avatar answered Oct 30 '22 09:10

JoeTidee