Re: Calculating the actual content width or height



On Dec 16, 2:15 pm, "Ben Amada" <ben.nojunkplease.am...@xxxxxxxxx>
wrote:
dhtml wrote:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
     "http://www.w3.org/TR/html4/loose.dtd";> <html lang="en"> <head>
<title>scrollWidth</title>
   <script type="text/javascript">
   onload = function() {
     var d = document.getElementById('d'),
       f = document.getElementById('f'),
       textContent = "textContent";
       if (! (textContent in document.body))
       textContent = "innerText";
       f[textContent] = d.scrollWidth;

   }; </script> </head> <body> <h1>scrollWidth</h1> <div id="d"
style="width: 10px; padding: 100px; background: lime">width: 10px;
padding: 100.5px</div> scrollWidth: <b id="f"></b> </body> </html>

FF 3 scrollWidth: 211

Safari 2, Safari 3, Opera 9.5: scrollWidth: 210

The OP was very specific in that he wants to obtain the content area. I
would also like a simple solution to this problem.

It doesn't seem scrollWidth takes the content width into consideration for
the OP's question.  My interpretation is that there is a single line of text

No need to interpret. Read the OP's response: "Thanx. Yes, that
worked." And the scrollWidth property is not a mystery.

that is being scrolled within a div.  If the width of that text is greater
than the div width, then scrollWidth just reports the width of the div.  I
modified your code to demonstrate this.

That's what he wanted. No need for a demonstration of scrollWidth.

[snip]
.



Relevant Pages

  • Re: Calculating the actual content width or height
    ... And the scrollWidth property is not a mystery. ... the div" is clearly not to be interpreted as the "content width" ... As for obtaining the width of the content area, when the element has padding, that is obtained by removing padding, then grabbing the scrollWidth:- ...
    (comp.lang.javascript)
  • Re: calculate amount of space required/resize div height
    ... the height of the div itself which would is fixed). ... That all sounds like it'd be better off being asked in a lightbox forum. ... on-topic here as you intend to access the DOM API with client-side ... The offsetWidth, offsetHeight, clientWidth, clientHeight, scrollWidth, ...
    (comp.lang.javascript)
  • Re: calculate amount of space required/resize div height
    ... the height of the div itself which would is fixed). ... That all sounds like it'd be better off being asked in a lightbox forum. ... on-topic here as you intend to access the DOM API with client-side ... The offsetWidth, offsetHeight, clientWidth, clientHeight, scrollWidth, ...
    (comp.lang.javascript)
  • Re: How to get amount of USABLE space in div?
    ... The div may or may not have a scrollbar. ... Or, instead of that kludge, you use the `scrollWidth' property of the ... using Javascript, without the padding. ... Yes, I must use javascript. ...
    (comp.lang.javascript)
  • Re: How to get amount of USABLE space in div?
    ... Jeff wrote: ... The div may or may not have a scrollbar. ... Try the `scrollWidth' and `scrollHeight' properties. ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.javascript)