Forum Moderators: open

Message Too Old, No Replies

Using DOM to get height of <div>?

I wish this site had a DOM forum...

         

Emperor

3:23 am on Oct 13, 2004 (gmt 0)

10+ Year Member



Hi guys,

I use JavaScript for my DOM work, I'm kinda new to DOM and was wondering if there is a method to get the height, in pixels, of a <div>.

I'm trying to make a scrolling web widget, or some kind of output control for a shoutbox type of thing.

Also, does anyone know of a good DOM reference, when I look at other people's scripts I see stuff I never knew existed. I usually use W3Schools but they don't have much on DOM.

Take care,
Emperor

Rambo Tribble

4:53 am on Oct 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The W3C does have a DOM reference, unfortunately browsers don't entirely or reliably implement it. IE is, perhaps, the worst of the popular browsers in this regard. The URL of the reference is: [w3.org...]

A generally more practical guide for real-world implementations is the Danny Goodman book Dynamic HTML on O'Reilly.

Probably the most reliable way to determine the height or width of an element is not part of the standardized DOM, but is a fairly standard part of browsers' DOM implementations, offsetHeight and offsetWidth Usually these values are extracted through the use of the element's ID, as in:

var elem_ht=document.getElementById("element_id").offsetHeight;