From 9e970f4e971f902e6d01adbd9428436f24aedb6f Mon Sep 17 00:00:00 2001 From: Arthur Verschaeve Date: Mon, 23 Feb 2015 21:40:30 +0100 Subject: [PATCH] css: add note about retrieving styles for detached elements --- entries/css.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/entries/css.xml b/entries/css.xml index 53ae097d..d77e55e9 100644 --- a/entries/css.xml +++ b/entries/css.xml @@ -21,6 +21,7 @@

Also, jQuery can equally interpret the CSS and DOM formatting of multiple-word properties. For example, jQuery understands and returns the correct value for both .css( "background-color" ) and .css( "backgroundColor" ).

Note that the computed style of an element may not be the same as the value specified for that element in a style sheet. For example, computed styles of dimensions are almost always pixels, but they can be specified as em, ex, px or % in a style sheet. Different browsers may return CSS color values that are logically but not textually equal, e.g., #FFF, #ffffff, and rgb(255,255,255).

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.

+

An element should be connected to the DOM when calling .css() on it. If it isn't, jQuery may throw an error.

As of jQuery 1.9, passing an array of style properties to .css() will result in an object of property-value pairs. For example, to retrieve all four rendered border-width values, you could use $( elem ).css([ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth" ]).