jQuery.cssNumber
ObjectThe .css() method uses jQuery.cssNumber
Object to see if it may append px
to unitless values.
By default, jQuery adds a "px" unit to the values passed to the .css()
method. If you want to prevent the .css() method from automatically adding the px unit for a specific CSS property, you can add the property to the jQuery.cssNumber object
$.cssNumber.someCSSProp = true;
jQuery.cssNumber
exampledefault
console.log($.cssNumber.left); // undefined $('#box').css('left',100); // It works, By default, jQuery adds a "px" unit
Prevent jQuery adding a "px" unit to the values by adding the property to the jQuery.cssNumber object
$.cssNumber.left = true; console.log($.cssNumber.left); // undefined $('#box').css('left',100); // not works