#179 ✓ duplicate
Julian Stahnke

Element.getWidth() using clientWidth/offsetWidth inconsistently, returning inconsistent results

Reported by Julian Stahnke | June 20th, 2008 @ 06:16 PM | in 1.6.0.3

The Element.getWidth() method returns this when the element is visible:

return {width: element.offsetWidth, height: element.offsetHeight};

But uses clientWidth/clientHeight when the element is invisible and the method does its show/hide stuff:

var originalWidth = element.clientWidth;

var originalHeight = element.clientHeight;

This yields inconsistent results when the element has borders. (clientWidth doesn’t seem to include the border-width—at least in Firefox 3 and Safari 3.1).

A fix would be to always use offsetWidth.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

The Prototype JavaScript library.

Shared Ticket Bins

Referenced by

Pages