Skip to content

Commit 23df8d8

Browse files
committed
.css(): Add new signature for 1.9
1 parent 2294f1d commit 23df8d8

1 file changed

Lines changed: 41 additions & 2 deletions

File tree

entries/css.xml

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99
<desc>A CSS property.</desc>
1010
</argument>
1111
</signature>
12-
<desc>Get the value of a style property for the first element in the set of matched elements.</desc>
12+
<signature>
13+
<added>1.9</added>
14+
<argument name="propertyNames" type="Array">
15+
<desc>An array of one or more CSS properties.</desc>
16+
</argument>
17+
</signature>
18+
<desc>Get the value of style properties for the first element in the set of matched elements.</desc>
1319
<longdesc>
1420
<p>The <code>.css()</code> method is a convenient way to get a style property from the first matched element, especially in light of the different ways browsers access most of those properties (the <code>getComputedStyle()</code> method in standards-based browsers versus the <code>currentStyle</code> and <code>runtimeStyle</code> properties in Internet Explorer) and the different terms browsers use for certain properties. For example, Internet Explorer's DOM implementation refers to the <code>float</code> property as <code>styleFloat</code>, while W3C standards-compliant browsers refer to it as <code>cssFloat</code>. For consistency, you can simply use <code>"float"</code>, and jQuery will translate it to the correct value for each browser.</p>
1521
<p>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 <code>.css('background-color')</code> and <code>.css('backgroundColor')</code>. Different browsers may return CSS color values that are logically but not textually equal, e.g., #FFF, #ffffff, and rgb(255,255,255).</p>
1622
<p>Shorthand CSS properties (e.g. margin, background, border) are not supported. For example, if you want to retrieve the rendered margin, use: <code>$(elem).css('marginTop')</code> and <code>$(elem).css('marginRight')</code>, and so on.</p>
23+
<p><strong>As of jQuery 1.9</strong>, passing an array of style properties to <code>.css()</code> will result in an object of property-value pairs.</p>
1724
</longdesc>
1825
<example>
19-
<desc>To access the background color of a clicked div.</desc>
26+
<desc>Get the background color of a clicked div.</desc>
2027
<code><![CDATA[
2128
$("div").click(function () {
2229
var color = $(this).css("background-color");
@@ -36,10 +43,42 @@ div { width:60px; height:60px; margin:5px; float:left; }
3643
<div style="background-color:#123456;"></div>
3744
<div style="background-color:#f11;"></div>]]></html>
3845
</example>
46+
47+
<example>
48+
<desc>Get the width, height, text color, and background color of a clicked div.</desc>
49+
<code><![CDATA[
50+
$("div").click(function () {
51+
var html = ["The clicked div has the following styles:"];
52+
53+
var styleProps = $(this).css( ["width", "height", "color", "background-color"] );
54+
$.each( styleProps, function( prop, value ) {
55+
html.push( prop + ": " + value );
56+
});
57+
58+
$( "#result" ).html( html.join( "<br>" ) );
59+
});
60+
61+
]]></code>
62+
<css><![CDATA[
63+
div { height: 50px; margin: 5px; padding: 5px; float: left; }
64+
65+
#box1 { width: 50px; color: yellow; background-color: blue; }
66+
#box2 { width: 80px; color: rgb(255,255,255); background-color: rgb(15,99,30); }
67+
#box3 { width: 40px; color: #fcc; background-color: #123456; }
68+
#box4 { width: 70px; background-color: #f11; }
69+
]]></css>
70+
<html><![CDATA[
71+
<p id="result">&nbsp;</p>
72+
<div id="box1">1</div>
73+
<div id="box2">2</div>
74+
<div id="box3">3</div>
75+
<div id="box4">4</div>]]></html>
76+
</example>
3977
<category slug="css"/>
4078
<category slug="manipulation/style-properties"/>
4179
<category slug="version/1.0"/>
4280
<category slug="version/1.4"/>
81+
<category slug="version/1.9"/>
4382
</entry>
4483
<entry type="method" name="css" return="jQuery">
4584
<signature>

0 commit comments

Comments
 (0)