3 test("css(String|Hash)", function() {
6 equals( jQuery('#main').css("display"), 'block', 'Check for css property "display"');
8 ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
9 jQuery('#nothiddendiv').css({display: 'none'});
10 ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
11 jQuery('#nothiddendiv').css({display: 'block'});
12 ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
14 var div = jQuery( "<div>" );
16 equals( div.css("width"), "auto", "Width on disconnected node." );
17 equals( div.css("height"), "auto", "Height on disconnected node." );
19 div.css({ width: 4, height: 4 });
21 equals( div.css("width"), "4px", "Width on disconnected node." );
22 equals( div.css("height"), "4px", "Height on disconnected node." );
24 var div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>").appendTo("body");
26 equals( div2.find("input").css("height"), "20px", "Height on hidden input." );
27 equals( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
28 equals( div2.find("div").css("height"), "20px", "Height on hidden textarea." );
32 // handle negative numbers by ignoring #1599, #4216
33 jQuery('#nothiddendiv').css({ 'width': 1, 'height': 1 });
35 var width = parseFloat(jQuery('#nothiddendiv').css('width')), height = parseFloat(jQuery('#nothiddendiv').css('height'));
36 jQuery('#nothiddendiv').css({ width: -1, height: -1 });
37 equals( parseFloat(jQuery('#nothiddendiv').css('width')), width, 'Test negative width ignored')
38 equals( parseFloat(jQuery('#nothiddendiv').css('height')), height, 'Test negative height ignored')
40 equals( jQuery('<div style="display: none;">').css('display'), 'none', 'Styles on disconnected nodes');
42 jQuery('#floatTest').css({'float': 'right'});
43 equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
44 jQuery('#floatTest').css({'font-size': '30px'});
45 equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
47 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
48 jQuery('#foo').css({opacity: n});
49 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
50 jQuery('#foo').css({opacity: parseFloat(n)});
51 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
53 jQuery('#foo').css({opacity: ''});
54 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
56 equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" );
57 jQuery('#empty').css({ opacity: '1' });
58 equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
60 var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild');
62 equals( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." );
63 equals( parseInt(div.css("font-size")), 16, "Verify fontSize px set." );
64 equals( parseInt(child.css("fontSize")), 16, "Verify fontSize px set." );
65 equals( parseInt(child.css("font-size")), 16, "Verify fontSize px set." );
67 child.css("height", "100%");
68 equals( child[0].style.height, "100%", "Make sure the height is being set correctly." );
70 child.attr("class", "em");
71 equals( parseInt(child.css("fontSize")), 32, "Verify fontSize em set." );
73 // Have to verify this as the result depends upon the browser's CSS
74 // support for font-size percentages
75 child.attr("class", "prct");
76 var prctval = parseInt(child.css("fontSize")), checkval = 0;
77 if ( prctval === 16 || prctval === 24 ) {
81 equals( prctval, checkval, "Verify fontSize % set." );
83 equals( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." );
85 var old = child[0].style.height;
88 child.css("height", parseFloat("zoo"));
89 equals( child[0].style.height, old, "Make sure height isn't changed on NaN." );
92 child.css("height", null);
93 equals( child[0].style.height, old, "Make sure height isn't changed on null." );
95 old = child[0].style.fontSize;
98 child.css("font-size", parseFloat("zoo"));
99 equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
102 child.css("font-size", null);
103 equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
106 test("css(String, Object)", function() {
109 ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
110 jQuery('#nothiddendiv').css("display", 'none');
111 ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
112 jQuery('#nothiddendiv').css("display", 'block');
113 ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
115 jQuery("#nothiddendiv").css("top", "-1em");
116 ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." );
118 jQuery('#floatTest').css('float', 'left');
119 equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
120 jQuery('#floatTest').css('font-size', '20px');
121 equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
123 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
124 jQuery('#foo').css('opacity', n);
125 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
126 jQuery('#foo').css('opacity', parseFloat(n));
127 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
129 jQuery('#foo').css('opacity', '');
130 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
132 // using contents will get comments regular, text, and comment nodes
133 var j = jQuery("#nonnodes").contents();
134 j.css("overflow", "visible");
135 equals( j.css("overflow"), "visible", "Check node,textnode,comment css works" );
136 // opera sometimes doesn't update 'display' correctly, see #2037
137 jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
138 equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
140 var div = jQuery("#nothiddendiv"),
141 display = div.css("display"),
142 ret = div.css("display", undefined);
144 equals( ret, div, "Make sure setting undefined returns the original set." );
145 equals( div.css("display"), display, "Make sure that the display wasn't changed." );
147 // Test for Bug #5509
150 jQuery('#foo').css("backgroundColor", "rgba(0, 0, 0, 0.1)");
155 ok( success, "Setting RGBA values does not throw Error" );
158 if ( !jQuery.support.opacity ) {
159 test("css(String, Object) for MSIE", function() {
160 // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
161 jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
162 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
164 var filterVal = "progid:DXImageTransform.Microsoft.Alpha(opacity=30) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
165 var filterVal2 = "progid:DXImageTransform.Microsoft.alpha(opacity=100) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
166 var filterVal3 = "progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
167 jQuery('#foo').css("filter", filterVal);
168 equals( jQuery('#foo').css("filter"), filterVal, "css('filter', val) works" );
169 jQuery('#foo').css("opacity", 1);
170 equals( jQuery('#foo').css("filter"), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" );
171 equals( jQuery('#foo').css("opacity"), 1, "Setting opacity in IE with other filters works" );
172 jQuery('#foo').css("filter", filterVal3).css("opacity", 1);
173 ok( jQuery('#foo').css("filter").indexOf(filterVal3) !== -1, "Setting opacity in IE doesn't clobber other filters" );
177 test("css(String, Function)", function() {
180 var sizes = ["10px", "20px", "30px"];
182 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
183 "<div class='cssFunction'></div>" +
184 "<div class='cssFunction'></div></div>")
189 jQuery("#cssFunctionTest div").css("font-size", function() {
190 var size = sizes[index];
197 jQuery("#cssFunctionTest div").each(function() {
198 var computedSize = jQuery(this).css("font-size")
199 var expectedSize = sizes[index]
200 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
204 jQuery("#cssFunctionTest").remove();
207 test("css(String, Function) with incoming value", function() {
210 var sizes = ["10px", "20px", "30px"];
212 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
213 "<div class='cssFunction'></div>" +
214 "<div class='cssFunction'></div></div>")
219 jQuery("#cssFunctionTest div").css("font-size", function() {
220 var size = sizes[index];
227 jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
228 var expectedSize = sizes[index]
229 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
234 jQuery("#cssFunctionTest").remove();
237 test("css(Object) where values are Functions", function() {
240 var sizes = ["10px", "20px", "30px"];
242 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
243 "<div class='cssFunction'></div>" +
244 "<div class='cssFunction'></div></div>")
249 jQuery("#cssFunctionTest div").css({fontSize: function() {
250 var size = sizes[index];
257 jQuery("#cssFunctionTest div").each(function() {
258 var computedSize = jQuery(this).css("font-size")
259 var expectedSize = sizes[index]
260 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
264 jQuery("#cssFunctionTest").remove();
267 test("css(Object) where values are Functions with incoming values", function() {
270 var sizes = ["10px", "20px", "30px"];
272 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
273 "<div class='cssFunction'></div>" +
274 "<div class='cssFunction'></div></div>")
279 jQuery("#cssFunctionTest div").css({fontSize: function() {
280 var size = sizes[index];
287 jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
288 var expectedSize = sizes[index]
289 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
294 jQuery("#cssFunctionTest").remove();
297 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
300 var $checkedtest = jQuery("#checkedtest");
301 // IE6 was clearing "checked" in jQuery.css(elem, "height");
302 jQuery.css($checkedtest[0], "height");
303 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
304 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
305 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
306 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
309 test(":visible selector works properly on table elements (bug #4512)", function () {
312 jQuery('#table').html('<tr><td style="display:none">cell</td><td>cell</td></tr>');
313 equals(jQuery('#table td:visible').length, 1, "hidden cell is not perceived as visible");
316 test(":visible selector works properly on children with a hidden parent (bug #4512)", function () {
318 jQuery('#table').css('display', 'none').html('<tr><td>cell</td><td>cell</td></tr>');
319 equals(jQuery('#table td:visible').length, 0, "hidden cell children not perceived as visible");