Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 8 years ago

#1599 closed bug (fixed)

Internet Explorer doesn't like negative values for CSS width

Reported by: kkaefer Owned by:
Priority: minor Milestone: 1.2.2
Component: core Version: 1.2
Keywords: Cc:
Blocked by: Blocking:

Description

The follwoing code causes IE (at least IE 7) to throw a script error:

$(function() { $('div').width(-1); });

(if .size() is > 0).

Obviously, it doesn't like negative values for width.

Change History (5)

comment:1 Changed 12 years ago by john

Priority: majorminor

This is a really minor issue - you shouldn't be setting negative widths to begin with - but I'm not a fan of throwing errors, so I'll look into it at some point.

comment:2 Changed 12 years ago by davidserduke

The CSS2.1 spec states "Negative values for 'width' are illegal."

http://www.w3.org/TR/CSS21/visudet.html#propdef-width

I suggest this bug be closed.

comment:3 Changed 12 years ago by brandon

Milestone: 1.2.11.2.2
need: PatchTest Case

What is the expected behavior? Should the width then be set to 0 instead of -1 or just ignored?

I would expect the result to be 0 but a quick run in firebug shows that firefox just ignores negative numbers for width and height.

I'm leaning towards fixing this so that the results while using jQuery are consistent cross-browser.

Index: jquery/src/core.js
===================================================================
--- jquery/src/core.js	(revision 3826)
+++ jquery/src/core.js	(working copy)
@@ -1058,7 +1058,8 @@
 				return letter.toUpperCase();
 			});
 
-			if ( value != undefined )
+			// ignore negative numbers for width and height
+			if ( value != undefined && (name.match(/^width|height$/) && parseFloat(value) > 0) )
 				elem[ name ] = value;
 
 			return elem[ name ];

comment:4 Changed 12 years ago by brandon

Actually should probably use the test method instead of match.

/^width|height$/.test(name)

comment:5 Changed 12 years ago by davidserduke

Resolution: fixed
Status: newclosed

Fixed in [3959] as Brandon suggested to ignore negative numbers for width and height css values.

Note: See TracTickets for help on using tickets.