JavaScript/CSS: how do I check if an element has overflowed?
December 11th, 2008
Something I want to know just infrequently enough. How is it done? How do I know, if I’ve got an element with “overflow:auto”, if it’s generated the scrollbar? And why do I want to know?
This is a handy technique when trying to, for instance, truncate unwieldy text within a fixed space. The trick?
Compare the element’s clientWidth (or clientHeight) to it’s scrollWidth (or scrollHeight). If the scrollWidth > clientWidth, the element has gone off the edge. Voila! Hopefully next time I need to remember this, I remember where I wrote it down.
Entry Filed under: Programming,Web Design

Leave a Comment
Some HTML allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Trackback this post | Subscribe to the comments via RSS Feed