Skip to main content

Bug Tracker

Side navigation

#4772 closed bug (cantfix)

Opened June 17, 2009 04:09AM UTC

Closed April 17, 2011 06:36PM UTC

Last modified March 15, 2012 03:30PM UTC

CSS get width property

Reported by: ventalator Owned by: brandon
Priority: low Milestone:
Component: dimensions Version: 1.3.2
Keywords: CSS, Width Cc:
Blocked by: Blocking:
Description

Currently when width has not been explicitly set in the CSS, jQuery returns the calculated width of the element. This is not the correct behavior because the default value of width is "auto".

If you access this property by the dom element.style.width it returns an empty string which is partially correct. Since jQuery is supposed to make things easier for developers shouldn't jQuery interpret this as the default value "auto"?

Attachments (0)
Change History (4)

Changed June 22, 2010 02:12AM UTC by dmethvin comment:1

When I have an empty div and do

$("div").css("width")
both IE and Firefox return "auto" but Chrome, Safari, and Opera return the actual width.
$("div").width()
always returns the actual dimensions on all browsers. So there is some inconsistency here. I would think .css() would return the requested width (for example, "33%") since we have .width() for the current pixel width.

Changed November 03, 2010 04:29PM UTC by boushley comment:2

I don't have IE to test on, but Chrome and Firefox (3.6.12) on Mac OSX return the actual width for .css("width") and they both return empty string for the width if you use .style.width. This can be tested here http://jsfiddle.net/boushley/MSyqR/2/

In version 1.4.2 .css("width") returned the actual value set in css only if it was set as an inline element style, if it was contained as external css then the calculated width is returned. As of 1.4.3 .css("width") always returns the calculated width no matter how the value is set.

I'm not sure which way we want to support but based on the description of the .css function http://api.jquery.com/css/ it would seem that we would want to return the 33% or empty string... although I would find that less helpful.

Changed November 03, 2010 06:14PM UTC by SlexAxton comment:3

milestone: 1.41.5
priority: minorlow
status: newassigned

Changed April 17, 2011 06:36PM UTC by john comment:4

resolution: → cantfix
status: assignedclosed

There is no way to get the "auto" state of an element reliably across all browsers so we return the computed value instead.