3 test("css(String|Hash)", function() {
6 equals( jQuery('#main').css("display"), 'none', '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 // handle negative numbers by ignoring #1599, #4216
15 jQuery('#nothiddendiv').css({ 'width': 1, 'height': 1 });
17 var width = parseFloat(jQuery('#nothiddendiv').css('width')), height = parseFloat(jQuery('#nothiddendiv').css('height'));
18 jQuery('#nothiddendiv').css({ width: -1, height: -1 });
19 equals( parseFloat(jQuery('#nothiddendiv').css('width')), width, 'Test negative width ignored')
20 equals( parseFloat(jQuery('#nothiddendiv').css('height')), height, 'Test negative height ignored')
22 jQuery('#floatTest').css({'float': 'right'});
23 equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
24 jQuery('#floatTest').css({'font-size': '30px'});
25 equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
27 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
28 jQuery('#foo').css({opacity: n});
29 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
30 jQuery('#foo').css({opacity: parseFloat(n)});
31 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
33 jQuery('#foo').css({opacity: ''});
34 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
36 equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" );
37 jQuery('#empty').css({ opacity: '1' });
38 equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
40 var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild');
42 equals( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." );
43 equals( parseInt(div.css("font-size")), 16, "Verify fontSize px set." );
44 equals( parseInt(child.css("fontSize")), 16, "Verify fontSize px set." );
45 equals( parseInt(child.css("font-size")), 16, "Verify fontSize px set." );
47 child.css("height", "100%");
48 equals( child[0].style.height, "100%", "Make sure the height is being set correctly." );
50 child.attr("class", "em");
51 equals( parseInt(child.css("fontSize")), 32, "Verify fontSize em set." );
53 // Have to verify this as the result depends upon the browser's CSS
54 // support for font-size percentages
55 child.attr("class", "prct");
56 var prctval = parseInt(child.css("fontSize")), checkval = 0;
57 if ( prctval === 16 || prctval === 24 ) {
61 equals( prctval, checkval, "Verify fontSize % set." );
63 equals( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." );
66 test("css(String, Object)", function() {
68 ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
69 jQuery('#nothiddendiv').css("display", 'none');
70 ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
71 jQuery('#nothiddendiv').css("display", 'block');
72 ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
74 jQuery("#nothiddendiv").css("top", "-1em");
75 ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." );
77 jQuery('#floatTest').css('float', 'left');
78 equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
79 jQuery('#floatTest').css('font-size', '20px');
80 equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
82 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
83 jQuery('#foo').css('opacity', n);
84 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
85 jQuery('#foo').css('opacity', parseFloat(n));
86 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
88 jQuery('#foo').css('opacity', '');
89 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
91 // using contents will get comments regular, text, and comment nodes
92 var j = jQuery("#nonnodes").contents();
93 j.css("padding-left", "1px");
94 equals( j.css("padding-left"), "1px", "Check node,textnode,comment css works" );
96 // opera sometimes doesn't update 'display' correctly, see #2037
97 jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
98 equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
101 if(jQuery.browser.msie) {
102 test("css(String, Object) for MSIE", function() {
103 // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
104 jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
105 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
107 var filterVal = "progid:DXImageTransform.Microsoft.alpha(opacity=30) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
108 var filterVal2 = "progid:DXImageTransform.Microsoft.alpha(opacity=100) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
109 jQuery('#foo').css("filter", filterVal);
110 equals( jQuery('#foo').css("filter"), filterVal, "css('filter', val) works" );
111 jQuery('#foo').css("opacity", 1)
112 equals( jQuery('#foo').css("filter"), filterVal2, "Setting opacity in IE doesn't clobber other filters" );
113 equals( jQuery('#foo').css("opacity"), 1, "Setting opacity in IE with other filters works" )
117 test("css(String, Function)", function() {
120 var sizes = ["10px", "20px", "30px"];
122 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
123 "<div class='cssFunction'></div>" +
124 "<div class='cssFunction'></div></div>")
129 jQuery("#cssFunctionTest div").css("font-size", function() {
130 var size = sizes[index];
137 jQuery("#cssFunctionTest div").each(function() {
138 var computedSize = jQuery(this).css("font-size")
139 var expectedSize = sizes[index]
140 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
144 jQuery("#cssFunctionTest").remove();
147 test("css(String, Function) with incoming value", function() {
150 var sizes = ["10px", "20px", "30px"];
152 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
153 "<div class='cssFunction'></div>" +
154 "<div class='cssFunction'></div></div>")
159 jQuery("#cssFunctionTest div").css("font-size", function() {
160 var size = sizes[index];
167 jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
168 var expectedSize = sizes[index]
169 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
174 jQuery("#cssFunctionTest").remove();
177 test("css(Object) where values are Functions", 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({fontSize: 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(Object) where values are Functions with incoming values", 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({fontSize: 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("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
240 var $checkedtest = jQuery("#checkedtest");
241 // IE6 was clearing "checked" in jQuery.css(elem, "height");
242 jQuery.css($checkedtest[0], "height");
243 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
244 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
245 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
246 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );