Bug Tracker

Ticket #7486 (closed bug: wontfix)

Opened 4 years ago

Last modified 23 months ago

css('height')

Reported by: anonymous Owned by: anonymous
Priority: low Milestone: 1.next
Component: css Version: 1.4.4
Keywords: regression Cc:
Blocking: Blocked by:

Description

Until now "$('#x').css('height')" returned 'auto', if no css-height was defined. Now it returns always the height, e.g. '35 px';

Change History

comment:1 Changed 4 years ago by addyosmani

  • Owner set to anonymous
  • Status changed from new to pending

Please supply a valid test case reproducing what you're trying to achieve, ideally on jsFiddle.net. This will allow us to investigate the problem described more thoroughly.

comment:2 Changed 4 years ago by anonymous

  • Status changed from pending to new

<p id="test">blabla</p> <script> alert( $('#test').css('height') ); </script>

Until jQuery 1.4.3: "auto" jQuery 1.4.4: e.g. "22px"

comment:3 Changed 4 years ago by danheberden

Probably related to fixes for #7225 http://bugs.jquery.com/ticket/7225

comment:4 Changed 4 years ago by danheberden

Can you please provide a live demo via jsfiddle.net? That helps a ton in looking into the problem :)

comment:5 Changed 4 years ago by snover

  • Keywords regression added
  • Status changed from new to open
  • Component changed from unfiled to css
  • Milestone changed from 1.5 to 1.4.5

This was noted on the commit notes for [53396b879bd29c090824da182e3cf69158829f82], though for whatever reason the ramifications of that change did not make it into the release notes. Now that there is an official report of this breaking someone’s stuff, I’m going to mark this and maybe we can revert this (though it is unlikely that the behaviour will change).

comment:6 Changed 4 years ago by anonymous

Hello,

Yes, it broke my app, but it was easy to fix. Maybe you should update the release notes and the API-docs.

Thanks Marcus

comment:7 Changed 4 years ago by jitter

  • Keywords needsdocs added

comment:8 Changed 4 years ago by Matt Palmerlee <mpalmerlee@…>

I have this same problem, it seems that this problem started in jQuery 1.4.3, not 1.4.4

Please see my jsFiddle test case here:  http://jsfiddle.net/mpalmerlee/DnRUG/

In 1.4.2 css("height") returns "auto" and in 1.4.3 and 1.4.4 it returns 0px in both IE and FF

comment:9 Changed 4 years ago by Matt Palmerlee <mpalmerlee@…>

In addition to this not working with height:auto, My test case doesn't work with height:100% in the div either.

Here is a forked jsFiddle test case with height:100%

 http://jsfiddle.net/mpalmerlee/rrMTZ/

This also works as expected in jQuery 1.4.2

comment:10 Changed 4 years ago by mpalmerlee

Correction to my last commend, here is the jsFiddle for the height 100% version:  http://jsfiddle.net/mpalmerlee/rrMTZ/1/

This breaks my app and is not as easy to fix for me as it was for anonymous, If I put in Height:16px for the div, my replaced input box looks ok in FF, but is too small in IE (IE wants input boxes ~ 20px high)

And if I specify Height:16px Firefox looks fine, but the input box is smaller in IE so this method doesn't work for me as well:

 http://jsfiddle.net/mpalmerlee/rrMTZ/2/

Version 0, edited 4 years ago by mpalmerlee (next)

comment:11 Changed 4 years ago by snover

mpalmerlee, investigate the box-sizing CSS property.

comment:12 Changed 4 years ago by mpalmerlee

snover,

Thanks for the pointer to the box-sizing CSS property, I was having trouble reproducing my application's behavior on jsFiddle in IE (the form elements looked fine when replaced when specifying an exact size like 16px). I finally realized that my application uses IE Quirks mode which I'm not able to simulate using jsFiddle, and it seems that the box-sizing properties don't work with IE quirks mode.

I've uploaded a test page to a server so that you can see the issue I have in IE:  http://ea1.conversive.com/jsFiddleJQueryHeightBug.html

Since it is not feasible to change my application from quirks mode because it would mean a ton of layout refactoring, and since I can't find another work around, I won't be able to upgrade from jQuery 1.4.2 to 1.4.4 until css('height') works how it does in 1.4.2 (height:auto or height:100% elements return auto and 100% respectively).

Thanks, -Matt

comment:13 Changed 3 years ago by timmywil

#8741 is a duplicate of this ticket.

comment:14 Changed 3 years ago by timmywil

  • Priority changed from undecided to low

jQuery.style gets uncomputed and looks like jQuery.css always gets computed. The question I think is, what should jQuery.fn.css return and is it specific to certain properties?

comment:15 Changed 3 years ago by mikesherov

Timmy, for what it's worth, isn't this exactly what cssHooks are for? Theoretically, a user could easily a cssHook to get the old behavior back:

Something like this... (untested)

jQuery.each(["height", "width"], function( i, name ) {
	jQuery.cssHooks[ name ] = {
		get: function( elem, computed, extra ) {
			return jQuery.style(elem, name);
		},

		set: function( elem, value ) {
						return jQuery.style(elem, name, value);
		}
	};
});

comment:16 Changed 3 years ago by timmywil

  • Status changed from open to closed
  • Resolution set to wontfix

I think we can safely say that this won't change, but a note on the docs would probably be good to indicate the change in behavior.

comment:17 Changed 3 years ago by anonymous

I need the ability to reset an element to 'height: auto' in some cases, but only if it was 'height: auto' or didn't have a height set to begin with.

jQuery.style still doesn't work for this. There does not appear to be a way to get information about styles that are not applied inline. In addition, I don't think that saying that this is "easily" achievable with an undocumented function is not really the best solution anyway...

 http://jsfiddle.net/CbcUR/5/

comment:18 Changed 3 years ago by rwaldron

@anonymous - see above, this can be resolved with a custom cssHook

comment:19 Changed 23 months ago by mikesherov

  • Keywords needsdocs removed
Note: See TracTickets for help on using tickets.