Bug Tracker

Ticket #4772 (closed bug: cantfix)

Opened 5 years ago

Last modified 3 years ago

CSS get width property

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

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

Change History

comment:1 Changed 4 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 4 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 4 years ago by SlexAxton

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

comment:4 Changed 4 years ago by john

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

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.