[Javascript] Re: Getting the width property of div

Paul Novitski paul at novitskisoftware.com
Tue Apr 5 12:45:14 CDT 2005


Shawn et al.,

As I recall, the reason for using object.offsetWidth instead of 
object.style.width is that offsetWidth represents the actual current width 
of the rendered object, whereas style.width represents the intended width 
as (and if) defined by a stylesheet or inline style.

With that reasoning, style.width can fail in browsers that allow elements 
to stretch to accommodate their contents in spite of explicit width 
styling, and will fail if the object hasn't been assigned a width in CSS.

Am I remembering this correctly?

Cheers,
Paul



At 10:25 AM 4/5/2005, Shawn Milo wrote:
>Forgive me if I'm missing something, but this seems to return 80 or
>NaN  for everything. Are you sure this is returning the width?
>
>Shawn
>
>On Apr 5, 2005 1:15 PM, Dash <forgetful54341087097153001984 at hotmail.com> 
>wrote:
> >
> > >Wow, who would have thought that this would be such a complex question?
> >
> > I don't think it is! parseInt because some brwsers might return a string
> > with px on the end or something.
> >
> > function hi(layerID){
> >     var width=parseInt(document.getElementById(layerID).style.width);
> >     alert(width);
> > }
> >
> > Dash xx
> > _______________________________________________
> > Javascript mailing list
> > Javascript at LaTech.edu
> > https://lists.LaTech.edu/mailman/listinfo/javascript
> >
> >
> >
>
>
>--
>Voicemail any time at:
>206-666-MILO
>_______________________________________________
>Javascript mailing list
>Javascript at LaTech.edu
>https://lists.LaTech.edu/mailman/listinfo/javascript





More information about the Javascript mailing list