Bug Tracker

Opened 6 years ago

Closed 5 years ago

Last modified 4 years ago

#4772 closed bug (cantfix)

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:


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"?

Change History (4)

comment:1 Changed 5 years ago by dmethvin

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.

comment:2 Changed 5 years ago by boushley

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.

comment:3 Changed 5 years ago by SlexAxton

  • Milestone changed from 1.4 to 1.5
  • Priority changed from minor to low
  • Status changed from new to assigned

comment:4 Changed 5 years ago by john

  • Resolution set to cantfix
  • Status changed from assigned to closed

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

Note: See TracTickets for help on using tickets.