jQuery Tutorial Tutorials - jQuery.cssNumber

jQuery.cssNumber Object

The .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 example

default

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
Date:2019-08-19 16:26:26 From:www.Lautturi.com author:Lautturi