1 module("css", { teardown: moduleTeardown });
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 // These should be "auto" (or some better value)
17 // temporarily provide "0px" for backwards compat
18 equals( div.css("width"), "0px", "Width on disconnected node." );
19 equals( div.css("height"), "0px", "Height on disconnected node." );
21 div.css({ width: 4, height: 4 });
23 equals( div.css("width"), "4px", "Width on disconnected node." );
24 equals( div.css("height"), "4px", "Height on disconnected node." );
26 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");
28 equals( div2.find("input").css("height"), "20px", "Height on hidden input." );
29 equals( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
30 equals( div2.find("div").css("height"), "20px", "Height on hidden textarea." );
34 // handle negative numbers by ignoring #1599, #4216
35 jQuery('#nothiddendiv').css({ 'width': 1, 'height': 1 });
37 var width = parseFloat(jQuery('#nothiddendiv').css('width')), height = parseFloat(jQuery('#nothiddendiv').css('height'));
38 jQuery('#nothiddendiv').css({ width: -1, height: -1 });
39 equals( parseFloat(jQuery('#nothiddendiv').css('width')), width, 'Test negative width ignored')
40 equals( parseFloat(jQuery('#nothiddendiv').css('height')), height, 'Test negative height ignored')
42 equals( jQuery('<div style="display: none;">').css('display'), 'none', 'Styles on disconnected nodes');
44 jQuery('#floatTest').css({'float': 'right'});
45 equals( jQuery('#floatTest').css('float'), 'right', 'Modified CSS float using "float": Assert float is right');
46 jQuery('#floatTest').css({'font-size': '30px'});
47 equals( jQuery('#floatTest').css('font-size'), '30px', 'Modified CSS font-size: Assert font-size is 30px');
49 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
50 jQuery('#foo').css({opacity: n});
51 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
52 jQuery('#foo').css({opacity: parseFloat(n)});
53 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
55 jQuery('#foo').css({opacity: ''});
56 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
58 equals( jQuery('#empty').css('opacity'), '0', "Assert opacity is accessible via filter property set in stylesheet in IE" );
59 jQuery('#empty').css({ opacity: '1' });
60 equals( jQuery('#empty').css('opacity'), '1', "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
62 var div = jQuery('#nothiddendiv'), child = jQuery('#nothiddendivchild');
64 equals( parseInt(div.css("fontSize")), 16, "Verify fontSize px set." );
65 equals( parseInt(div.css("font-size")), 16, "Verify fontSize px set." );
66 equals( parseInt(child.css("fontSize")), 16, "Verify fontSize px set." );
67 equals( parseInt(child.css("font-size")), 16, "Verify fontSize px set." );
69 child.css("height", "100%");
70 equals( child[0].style.height, "100%", "Make sure the height is being set correctly." );
72 child.attr("class", "em");
73 equals( parseInt(child.css("fontSize")), 32, "Verify fontSize em set." );
75 // Have to verify this as the result depends upon the browser's CSS
76 // support for font-size percentages
77 child.attr("class", "prct");
78 var prctval = parseInt(child.css("fontSize")), checkval = 0;
79 if ( prctval === 16 || prctval === 24 ) {
83 equals( prctval, checkval, "Verify fontSize % set." );
85 equals( typeof child.css("width"), "string", "Make sure that a string width is returned from css('width')." );
87 var old = child[0].style.height;
90 child.css("height", parseFloat("zoo"));
91 equals( child[0].style.height, old, "Make sure height isn't changed on NaN." );
94 child.css("height", null);
95 equals( child[0].style.height, old, "Make sure height isn't changed on null." );
97 old = child[0].style.fontSize;
100 child.css("font-size", parseFloat("zoo"));
101 equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
104 child.css("font-size", null);
105 equals( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
108 test("css(String, Object)", function() {
111 ok( jQuery('#nothiddendiv').is(':visible'), 'Modifying CSS display: Assert element is visible');
112 jQuery('#nothiddendiv').css("display", 'none');
113 ok( !jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is hidden');
114 jQuery('#nothiddendiv').css("display", 'block');
115 ok( jQuery('#nothiddendiv').is(':visible'), 'Modified CSS display: Assert element is visible');
117 jQuery("#nothiddendiv").css("top", "-1em");
118 ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." );
120 jQuery('#floatTest').css('float', 'left');
121 equals( jQuery('#floatTest').css('float'), 'left', 'Modified CSS float using "float": Assert float is left');
122 jQuery('#floatTest').css('font-size', '20px');
123 equals( jQuery('#floatTest').css('font-size'), '20px', 'Modified CSS font-size: Assert font-size is 20px');
125 jQuery.each("0,0.25,0.5,0.75,1".split(','), function(i, n) {
126 jQuery('#foo').css('opacity', n);
127 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
128 jQuery('#foo').css('opacity', parseFloat(n));
129 equals( jQuery('#foo').css('opacity'), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
131 jQuery('#foo').css('opacity', '');
132 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when set to an empty String" );
134 // using contents will get comments regular, text, and comment nodes
135 var j = jQuery("#nonnodes").contents();
136 j.css("overflow", "visible");
137 equals( j.css("overflow"), "visible", "Check node,textnode,comment css works" );
138 // opera sometimes doesn't update 'display' correctly, see #2037
139 jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML
140 equals( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
142 var div = jQuery("#nothiddendiv"),
143 display = div.css("display"),
144 ret = div.css("display", undefined);
146 equals( ret, div, "Make sure setting undefined returns the original set." );
147 equals( div.css("display"), display, "Make sure that the display wasn't changed." );
149 // Test for Bug #5509
152 jQuery('#foo').css("backgroundColor", "rgba(0, 0, 0, 0.1)");
157 ok( success, "Setting RGBA values does not throw Error" );
160 if ( !jQuery.support.opacity ) {
161 test("css(String, Object) for MSIE", function() {
162 // for #1438, IE throws JS error when filter exists but doesn't have opacity in it
163 jQuery('#foo').css("filter", "progid:DXImageTransform.Microsoft.Chroma(color='red');");
164 equals( jQuery('#foo').css('opacity'), '1', "Assert opacity is 1 when a different filter is set in IE, #1438" );
166 var filterVal = "progid:DXImageTransform.Microsoft.Alpha(opacity=30) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
167 var filterVal2 = "progid:DXImageTransform.Microsoft.alpha(opacity=100) progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
168 var filterVal3 = "progid:DXImageTransform.Microsoft.Blur(pixelradius=5)";
169 jQuery('#foo').css("filter", filterVal);
170 equals( jQuery('#foo').css("filter"), filterVal, "css('filter', val) works" );
171 jQuery('#foo').css("opacity", 1);
172 equals( jQuery('#foo').css("filter"), filterVal2, "Setting opacity in IE doesn't duplicate opacity filter" );
173 equals( jQuery('#foo').css("opacity"), 1, "Setting opacity in IE with other filters works" );
174 jQuery('#foo').css("filter", filterVal3).css("opacity", 1);
175 ok( jQuery('#foo').css("filter").indexOf(filterVal3) !== -1, "Setting opacity in IE doesn't clobber other filters" );
179 test("css(String, Function)", function() {
182 var sizes = ["10px", "20px", "30px"];
184 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
185 "<div class='cssFunction'></div>" +
186 "<div class='cssFunction'></div></div>")
191 jQuery("#cssFunctionTest div").css("font-size", function() {
192 var size = sizes[index];
199 jQuery("#cssFunctionTest div").each(function() {
200 var computedSize = jQuery(this).css("font-size")
201 var expectedSize = sizes[index]
202 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
206 jQuery("#cssFunctionTest").remove();
209 test("css(String, Function) with incoming value", function() {
212 var sizes = ["10px", "20px", "30px"];
214 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
215 "<div class='cssFunction'></div>" +
216 "<div class='cssFunction'></div></div>")
221 jQuery("#cssFunctionTest div").css("font-size", function() {
222 var size = sizes[index];
229 jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
230 var expectedSize = sizes[index]
231 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
236 jQuery("#cssFunctionTest").remove();
239 test("css(Object) where values are Functions", function() {
242 var sizes = ["10px", "20px", "30px"];
244 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
245 "<div class='cssFunction'></div>" +
246 "<div class='cssFunction'></div></div>")
251 jQuery("#cssFunctionTest div").css({fontSize: function() {
252 var size = sizes[index];
259 jQuery("#cssFunctionTest div").each(function() {
260 var computedSize = jQuery(this).css("font-size")
261 var expectedSize = sizes[index]
262 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
266 jQuery("#cssFunctionTest").remove();
269 test("css(Object) where values are Functions with incoming values", function() {
272 var sizes = ["10px", "20px", "30px"];
274 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
275 "<div class='cssFunction'></div>" +
276 "<div class='cssFunction'></div></div>")
281 jQuery("#cssFunctionTest div").css({fontSize: function() {
282 var size = sizes[index];
289 jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
290 var expectedSize = sizes[index]
291 equals( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
296 jQuery("#cssFunctionTest").remove();
299 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
302 var $checkedtest = jQuery("#checkedtest");
303 // IE6 was clearing "checked" in jQuery.css(elem, "height");
304 jQuery.css($checkedtest[0], "height");
305 ok( !! jQuery(":radio:first", $checkedtest).attr("checked"), "Check first radio still checked." );
306 ok( ! jQuery(":radio:last", $checkedtest).attr("checked"), "Check last radio still NOT checked." );
307 ok( !! jQuery(":checkbox:first", $checkedtest).attr("checked"), "Check first checkbox still checked." );
308 ok( ! jQuery(":checkbox:last", $checkedtest).attr("checked"), "Check last checkbox still NOT checked." );
311 test(":visible selector works properly on table elements (bug #4512)", function () {
314 jQuery('#table').html('<tr><td style="display:none">cell</td><td>cell</td></tr>');
315 equals(jQuery('#table td:visible').length, 1, "hidden cell is not perceived as visible");
318 test(":visible selector works properly on children with a hidden parent (bug #4512)", function () {
320 jQuery('#table').css('display', 'none').html('<tr><td>cell</td><td>cell</td></tr>');
321 equals(jQuery('#table td:visible').length, 0, "hidden cell children not perceived as visible");