This is now confirmed in the official docs: http://api.jquery.com/css/
Setter ( .css( propertyName, value )
)
As of jQuery 1.8, the .css()
setter will automatically take care of prefixing the property name. For example, take .css( "user-select", "none" )
in Chrome/Safari will set it as -webkit-user-select
, Firefox will use -moz-user-select
, and IE10 will use -ms-user-select
.
Getter ( .css( propertyName )
)
The .css()
method is a convenient way to get a computed style property from the first matched element, especially in light of the different ways browsers access most of those properties (the getComputedStyle()
method in standards-based browsers versus the currentStyle
and runtimeStyle
properties in Internet Explorer prior to version 9) and the different terms browsers use for certain properties. For example, Internet Explorer's DOM implementation refers to the float property as styleFloat
, while W3C standards-compliant browsers refer to it as cssFloat
. For consistency, you can simply use "float"
, and jQuery will translate it to the correct value for each browser.
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 as border-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:
Retrieval of shorthand CSS properties (e.g., margin, background, border), although functional with some browsers, is not guaranteed. For example, if you want to retrieve the rendered border-width
, use: $( elem ).css( "borderTopWidth" )
, $( elem ).css( "borderBottomWidth" )
, and so on.
border-radius
, you can probably drop the prefixes anyway; it's been standardised for long enough that there's really not many browsers out there in the wild that still need the prefix. See caniuse.com/#search=border-radius – Tourer