I have some code:
$("#" + this.id).css("border-radius",this.radius + "px");
$("#" + this.id).css("-moz-border-radius",this.radius + "px");
$("#" + this.id).css("-webkit-border-radius",this.radius + "px");
I am trying to improve lines like this by using JSON to apply them (as shown in jQuery's docs) or by removing the vendor prefix versions completely.
Does jQuery's .css()
method automatically apply any required vendor prefixes when changing CSS properties on an element?
This is now confirmed in the official docs: http://api.jquery.com/css/
Setter (
.css( propertyName, value )
)Getter (
.css( propertyName )
)It doesn't explicitly mention vendor prefixes in the getter context but it's easy to test. For example,
$element.css('border-radius')
on Chrome returns values set asborder-radius
or-webkit-border-radius
and ignores values set as-moz-border-radius
.Just keep in mind that it's inconsistent across browsers for shorthand properties:
As @zeroflagL wrote it appears that since jQuery 1.8.0
.css()
does add browser specific prefixes (see this).In earlier versions this is not done automatically by jQuery's
.css()
. You will have to do it by yourself or you can use jQuery's.cssHooks()
to add vendor prefixes.Code example from here:
jQuery DOES add vendor prefixes. It first checks for the presence of the standard property and if it's not found for a vendor prefixed version. From the source:
I don't know since which version, but I think 1.8.