3 QUnit.module( "css", { teardown: moduleTeardown } );
5 QUnit.test( "css(String|Hash)", function( assert ) {
8 assert.equal( jQuery( "#qunit-fixture" ).css( "display" ), "block", "Check for css property \"display\"" );
10 var $child, div, div2, width, height, child, prctval, checkval, old;
12 $child = jQuery( "#nothiddendivchild" ).css( { "width": "20%", "height": "20%" } );
13 assert.notEqual( $child.css( "width" ), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" );
14 assert.notEqual( $child.css( "height" ), "20px", "Retrieving a height percentage on the child of a hidden div returns percentage" );
16 div = jQuery( "<div/>" );
18 // These should be "auto" (or some better value)
19 // temporarily provide "0px" for backwards compat
20 assert.equal( div.css( "width" ), "0px", "Width on disconnected node." );
21 assert.equal( div.css( "height" ), "0px", "Height on disconnected node." );
23 div.css( { "width": 4, "height": 4 } );
25 assert.equal( div.css( "width" ), "4px", "Width on disconnected node." );
26 assert.equal( div.css( "height" ), "4px", "Height on disconnected node." );
28 div2 = jQuery( "<div style='display:none;'><input type='text' style='height:20px;'/><textarea style='height:20px;'/><div style='height:20px;'></div></div>" ).appendTo( "body" );
30 assert.equal( div2.find( "input" ).css( "height" ), "20px", "Height on hidden input." );
31 assert.equal( div2.find( "textarea" ).css( "height" ), "20px", "Height on hidden textarea." );
32 assert.equal( div2.find( "div" ).css( "height" ), "20px", "Height on hidden div." );
36 // handle negative numbers by setting to zero #11604
37 jQuery( "#nothiddendiv" ).css( { "width": 1, "height": 1 } );
39 width = parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) );
40 height = parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) );
41 jQuery( "#nothiddendiv" ).css( { "overflow":"hidden", "width": -1, "height": -1 } );
42 assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "width" ) ), 0, "Test negative width set to 0" );
43 assert.equal( parseFloat( jQuery( "#nothiddendiv" ).css( "height" ) ), 0, "Test negative height set to 0" );
45 assert.equal( jQuery( "<div style='display: none;'/>" ).css( "display" ), "none", "Styles on disconnected nodes" );
47 jQuery( "#floatTest" ).css( { "float": "right" } );
48 assert.equal( jQuery( "#floatTest" ).css( "float" ), "right", "Modified CSS float using \"float\": Assert float is right" );
49 jQuery( "#floatTest" ).css( { "font-size": "30px" } );
50 assert.equal( jQuery( "#floatTest" ).css( "font-size" ), "30px", "Modified CSS font-size: Assert font-size is 30px" );
51 jQuery.each( "0,0.25,0.5,0.75,1".split( "," ), function( i, n ) {
52 jQuery( "#foo" ).css( { "opacity": n } );
54 assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a String" );
55 jQuery( "#foo" ).css( { "opacity": parseFloat( n ) } );
56 assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a Number" );
58 jQuery( "#foo" ).css( { "opacity": "" } );
59 assert.equal( jQuery( "#foo" ).css( "opacity" ), "1", "Assert opacity is 1 when set to an empty String" );
61 assert.equal( jQuery( "#empty" ).css( "opacity" ), "0", "Assert opacity is accessible" );
62 jQuery( "#empty" ).css( { "opacity": "1" } );
63 assert.equal( jQuery( "#empty" ).css( "opacity" ), "1", "Assert opacity is taken from style attribute when set" );
65 div = jQuery( "#nothiddendiv" );
66 child = jQuery( "#nothiddendivchild" );
68 assert.equal( parseInt( div.css( "fontSize" ), 10 ), 16, "Verify fontSize px set." );
69 assert.equal( parseInt( div.css( "font-size" ), 10 ), 16, "Verify fontSize px set." );
70 assert.equal( parseInt( child.css( "fontSize" ), 10 ), 16, "Verify fontSize px set." );
71 assert.equal( parseInt( child.css( "font-size" ), 10 ), 16, "Verify fontSize px set." );
73 child.css( "height", "100%" );
74 assert.equal( child[ 0 ].style.height, "100%", "Make sure the height is being set correctly." );
76 child.attr( "class", "em" );
77 assert.equal( parseInt( child.css( "fontSize" ), 10 ), 32, "Verify fontSize em set." );
79 // Have to verify this as the result depends upon the browser's CSS
80 // support for font-size percentages
81 child.attr( "class", "prct" );
82 prctval = parseInt( child.css( "fontSize" ), 10 );
84 if ( prctval === 16 || prctval === 24 ) {
88 assert.equal( prctval, checkval, "Verify fontSize % set." );
90 assert.equal( typeof child.css( "width" ), "string", "Make sure that a string width is returned from css('width')." );
92 old = child[ 0 ].style.height;
95 child.css( "height", parseFloat( "zoo" ) );
96 assert.equal( child[ 0 ].style.height, old, "Make sure height isn't changed on NaN." );
99 child.css( "height", null );
100 assert.equal( child[ 0 ].style.height, old, "Make sure height isn't changed on null." );
102 old = child[ 0 ].style.fontSize;
105 child.css( "font-size", parseFloat( "zoo" ) );
106 assert.equal( child[ 0 ].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
109 child.css( "font-size", null );
110 assert.equal( child[ 0 ].style.fontSize, old, "Make sure font-size isn't changed on null." );
112 assert.strictEqual( child.css( "x-fake" ), undefined, "Make sure undefined is returned from css(nonexistent)." );
114 div = jQuery( "<div/>" ).css( { position: "absolute", "z-index": 1000 } ).appendTo( "#qunit-fixture" );
115 assert.strictEqual( div.css( "z-index" ), "1000",
116 "Make sure that a string z-index is returned from css('z-index') (#14432)." );
119 QUnit.test( "css() explicit and relative values", function( assert ) {
122 var $elem = jQuery( "#nothiddendiv" );
124 $elem.css( { "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 } );
125 assert.equal( $elem.css( "width" ), "1px", "Initial css set or width/height works (hash)" );
126 assert.equal( $elem.css( "paddingLeft" ), "1px", "Initial css set of paddingLeft works (hash)" );
127 assert.equal( $elem.css( "opacity" ), "1", "Initial css set of opacity works (hash)" );
129 $elem.css( { width: "+=9" } );
130 assert.equal( $elem.css( "width" ), "10px", "'+=9' on width (hash)" );
132 $elem.css( { "width": "-=9" } );
133 assert.equal( $elem.css( "width" ), "1px", "'-=9' on width (hash)" );
135 $elem.css( { "width": "+=9px" } );
136 assert.equal( $elem.css( "width" ), "10px", "'+=9px' on width (hash)" );
138 $elem.css( { "width": "-=9px" } );
139 assert.equal( $elem.css( "width" ), "1px", "'-=9px' on width (hash)" );
141 $elem.css( "width", "+=9" );
142 assert.equal( $elem.css( "width" ), "10px", "'+=9' on width (params)" );
144 $elem.css( "width", "-=9" );
145 assert.equal( $elem.css( "width" ), "1px", "'-=9' on width (params)" );
147 $elem.css( "width", "+=9px" );
148 assert.equal( $elem.css( "width" ), "10px", "'+=9px' on width (params)" );
150 $elem.css( "width", "-=9px" );
151 assert.equal( $elem.css( "width" ), "1px", "'-=9px' on width (params)" );
153 $elem.css( "width", "-=-9px" );
154 assert.equal( $elem.css( "width" ), "10px", "'-=-9px' on width (params)" );
156 $elem.css( "width", "+=-9px" );
157 assert.equal( $elem.css( "width" ), "1px", "'+=-9px' on width (params)" );
159 $elem.css( { "paddingLeft": "+=4" } );
160 assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on paddingLeft (hash)" );
162 $elem.css( { "paddingLeft": "-=4" } );
163 assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on paddingLeft (hash)" );
165 $elem.css( { "paddingLeft": "+=4px" } );
166 assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on paddingLeft (hash)" );
168 $elem.css( { "paddingLeft": "-=4px" } );
169 assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on paddingLeft (hash)" );
171 $elem.css( { "padding-left": "+=4" } );
172 assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on padding-left (hash)" );
174 $elem.css( { "padding-left": "-=4" } );
175 assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on padding-left (hash)" );
177 $elem.css( { "padding-left": "+=4px" } );
178 assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on padding-left (hash)" );
180 $elem.css( { "padding-left": "-=4px" } );
181 assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on padding-left (hash)" );
183 $elem.css( "paddingLeft", "+=4" );
184 assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4' on paddingLeft (params)" );
186 $elem.css( "paddingLeft", "-=4" );
187 assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4' on paddingLeft (params)" );
189 $elem.css( "padding-left", "+=4px" );
190 assert.equal( $elem.css( "paddingLeft" ), "5px", "'+=4px' on padding-left (params)" );
192 $elem.css( "padding-left", "-=4px" );
193 assert.equal( $elem.css( "paddingLeft" ), "1px", "'-=4px' on padding-left (params)" );
195 $elem.css( { "opacity": "-=0.5" } );
196 assert.equal( $elem.css( "opacity" ), "0.5", "'-=0.5' on opacity (hash)" );
198 $elem.css( { "opacity": "+=0.5" } );
199 assert.equal( $elem.css( "opacity" ), "1", "'+=0.5' on opacity (hash)" );
201 $elem.css( "opacity", "-=0.5" );
202 assert.equal( $elem.css( "opacity" ), "0.5", "'-=0.5' on opacity (params)" );
204 $elem.css( "opacity", "+=0.5" );
205 assert.equal( $elem.css( "opacity" ), "1", "'+=0.5' on opacity (params)" );
208 QUnit.test( "css() non-px relative values (gh-1711)", function( assert ) {
213 $child = jQuery( "#nothiddendivchild" ),
214 add = function( prop, val, unit ) {
216 adjustment = ( val < 0 ? "-=" : "+=" ) + Math.abs( val ) + unit,
217 message = prop + ": " + adjustment,
219 expected = cssOld + val * units[ prop ][ unit ];
222 $child.css( prop, adjustment );
223 cssCurrent = parseFloat( $child.css( prop ) );
224 message += " (actual " + round( cssCurrent, 2 ) + "px, expected " +
225 round( expected, 2 ) + "px)";
227 // Require a difference of no more than one pixel
228 difference = Math.abs( cssCurrent - expected );
229 assert.ok( difference <= 1, message );
231 getUnits = function( prop ) {
234 "em": parseFloat( $child.css( prop, "100em" ).css( prop ) ) / 100,
235 "pt": parseFloat( $child.css( prop, "100pt" ).css( prop ) ) / 100,
236 "pc": parseFloat( $child.css( prop, "100pc" ).css( prop ) ) / 100,
237 "cm": parseFloat( $child.css( prop, "100cm" ).css( prop ) ) / 100,
238 "mm": parseFloat( $child.css( prop, "100mm" ).css( prop ) ) / 100,
239 "%": parseFloat( $child.css( prop, "500%" ).css( prop ) ) / 500
242 round = function( num, fractionDigits ) {
243 var base = Math.pow( 10, fractionDigits );
244 return Math.round( num * base ) / base;
247 jQuery( "#nothiddendiv" ).css( { height: 1, padding: 0, width: 400 } );
248 $child.css( { height: 1, padding: 0 } );
251 cssCurrent = parseFloat( $child.css( "width", "50%" ).css( "width" ) );
252 add( "width", 25, "%" );
253 add( "width", -50, "%" );
254 add( "width", 10, "em" );
255 add( "width", 10, "pt" );
256 add( "width", -2.3, "pt" );
257 add( "width", 5, "pc" );
258 add( "width", -5, "em" );
259 add( "width", +2, "cm" );
260 add( "width", -15, "mm" );
261 add( "width", 21, "px" );
263 getUnits( "lineHeight" );
264 cssCurrent = parseFloat( $child.css( "lineHeight", "1em" ).css( "lineHeight" ) );
265 add( "lineHeight", 50, "%" );
266 add( "lineHeight", 2, "em" );
267 add( "lineHeight", -10, "px" );
268 add( "lineHeight", 20, "pt" );
269 add( "lineHeight", 30, "pc" );
270 add( "lineHeight", 1, "cm" );
271 add( "lineHeight", -44, "mm" );
274 QUnit.test( "css() mismatched relative values with bounded styles (gh-2144)", function( assert ) {
278 $container = jQuery( "<div/>" )
279 .css( { position: "absolute", width: "400px", fontSize: "4px" } )
280 .appendTo( "#qunit-fixture" ),
281 $el = jQuery( "<div/>" )
282 .css( { position: "absolute", left: "50%", right: "50%" } )
283 .appendTo( $container );
285 $el.css( "right", "-=25em" );
286 assert.equal( Math.round( parseFloat( $el.css( "right" ) ) ), 100,
287 "Constraints do not interfere with unit conversion" );
290 QUnit.test( "css(String, Object)", function( assert ) {
292 var j, div, display, ret, success;
294 jQuery( "#floatTest" ).css( "float", "left" );
295 assert.equal( jQuery( "#floatTest" ).css( "float" ), "left", "Modified CSS float using \"float\": Assert float is left" );
296 jQuery( "#floatTest" ).css( "font-size", "20px" );
297 assert.equal( jQuery( "#floatTest" ).css( "font-size" ), "20px", "Modified CSS font-size: Assert font-size is 20px" );
299 jQuery.each( "0,0.25,0.5,0.75,1".split( "," ), function( i, n ) {
300 jQuery( "#foo" ).css( "opacity", n );
301 assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a String" );
302 jQuery( "#foo" ).css( "opacity", parseFloat( n ) );
303 assert.equal( jQuery( "#foo" ).css( "opacity" ), parseFloat( n ), "Assert opacity is " + parseFloat( n ) + " as a Number" );
305 jQuery( "#foo" ).css( "opacity", "" );
306 assert.equal( jQuery( "#foo" ).css( "opacity" ), "1", "Assert opacity is 1 when set to an empty String" );
308 // using contents will get comments regular, text, and comment nodes
309 j = jQuery( "#nonnodes" ).contents();
310 j.css( "overflow", "visible" );
311 assert.equal( j.css( "overflow" ), "visible", "Check node,textnode,comment css works" );
312 assert.equal( jQuery( "#t2037 .hidden" ).css( "display" ), "none", "Make sure browser thinks it is hidden" );
314 div = jQuery( "#nothiddendiv" );
315 display = div.css( "display" );
316 ret = div.css( "display", undefined );
318 assert.equal( ret, div, "Make sure setting undefined returns the original set." );
319 assert.equal( div.css( "display" ), display, "Make sure that the display wasn't changed." );
323 jQuery( "#foo" ).css( "backgroundColor", "rgba(0, 0, 0, 0.1)" );
328 assert.ok( success, "Setting RGBA values does not throw Error (#5509)" );
330 jQuery( "#foo" ).css( "font", "7px/21px sans-serif" );
331 assert.strictEqual( jQuery( "#foo" ).css( "line-height" ), "21px",
332 "Set font shorthand property (#14759)" );
335 QUnit.test( "css(String, Object) with negative values", function( assert ) {
338 jQuery( "#nothiddendiv" ).css( "margin-top", "-10px" );
339 jQuery( "#nothiddendiv" ).css( "margin-left", "-10px" );
340 assert.equal( jQuery( "#nothiddendiv" ).css( "margin-top" ), "-10px", "Ensure negative top margins work." );
341 assert.equal( jQuery( "#nothiddendiv" ).css( "margin-left" ), "-10px", "Ensure negative left margins work." );
343 jQuery( "#nothiddendiv" ).css( "position", "absolute" );
344 jQuery( "#nothiddendiv" ).css( "top", "-20px" );
345 jQuery( "#nothiddendiv" ).css( "left", "-20px" );
346 assert.equal( jQuery( "#nothiddendiv" ).css( "top" ), "-20px", "Ensure negative top values work." );
347 assert.equal( jQuery( "#nothiddendiv" ).css( "left" ), "-20px", "Ensure negative left values work." );
350 QUnit.test( "css(Array)", function( assert ) {
354 "overflow": "visible",
360 elem = jQuery( "<div></div>" ).appendTo( "#qunit-fixture" );
362 assert.deepEqual( elem.css( expectedMany ).css( [ "overflow", "width" ] ), expectedMany, "Getting multiple element array" );
363 assert.deepEqual( elem.css( expectedSingle ).css( [ "width" ] ), expectedSingle, "Getting single element array" );
366 QUnit.test( "css(String, Function)", function( assert ) {
370 sizes = [ "10px", "20px", "30px" ];
372 jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" +
373 "<div class='cssFunction'></div>" +
374 "<div class='cssFunction'></div></div>" )
379 jQuery( "#cssFunctionTest div" ).css( "font-size", function() {
380 var size = sizes[ index ];
387 jQuery( "#cssFunctionTest div" ).each( function() {
388 var computedSize = jQuery( this ).css( "font-size" ),
389 expectedSize = sizes[ index ];
390 assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
394 jQuery( "#cssFunctionTest" ).remove();
397 QUnit.test( "css(String, Function) with incoming value", function( assert ) {
401 sizes = [ "10px", "20px", "30px" ];
403 jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" +
404 "<div class='cssFunction'></div>" +
405 "<div class='cssFunction'></div></div>" )
410 jQuery( "#cssFunctionTest div" ).css( "font-size", function() {
411 var size = sizes[ index ];
418 jQuery( "#cssFunctionTest div" ).css( "font-size", function( i, computedSize ) {
419 var expectedSize = sizes[ index ];
420 assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
425 jQuery( "#cssFunctionTest" ).remove();
428 QUnit.test( "css(Object) where values are Functions", function( assert ) {
432 sizes = [ "10px", "20px", "30px" ];
434 jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" +
435 "<div class='cssFunction'></div>" +
436 "<div class='cssFunction'></div></div>" )
441 jQuery( "#cssFunctionTest div" ).css( { "fontSize": function() {
442 var size = sizes[ index ];
449 jQuery( "#cssFunctionTest div" ).each( function() {
450 var computedSize = jQuery( this ).css( "font-size" ),
451 expectedSize = sizes[ index ];
452 assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
456 jQuery( "#cssFunctionTest" ).remove();
459 QUnit.test( "css(Object) where values are Functions with incoming values", function( assert ) {
463 sizes = [ "10px", "20px", "30px" ];
465 jQuery( "<div id='cssFunctionTest'><div class='cssFunction'></div>" +
466 "<div class='cssFunction'></div>" +
467 "<div class='cssFunction'></div></div>" )
472 jQuery( "#cssFunctionTest div" ).css( { "fontSize": function() {
473 var size = sizes[ index ];
480 jQuery( "#cssFunctionTest div" ).css( { "font-size": function( i, computedSize ) {
481 var expectedSize = sizes[ index ];
482 assert.equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
487 jQuery( "#cssFunctionTest" ).remove();
490 // .show(), .hide(), can be excluded from the build
491 if ( jQuery.fn.show && jQuery.fn.hide ) {
493 QUnit.test( "show()", function( assert ) {
497 var hiddendiv, div, pass, test;
498 hiddendiv = jQuery( "div.hidden" );
500 assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "none", "hiddendiv is display: none" );
502 hiddendiv.css( "display", "block" );
503 assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
506 assert.equal( jQuery.css( hiddendiv[ 0 ], "display" ), "block", "hiddendiv is display: block" );
508 hiddendiv.css( "display", "" );
511 div = jQuery( "#qunit-fixture div" );
512 div.show().each( function() {
513 if ( this.style.display === "none" ) {
517 assert.ok( pass, "Show" );
520 "<div id='show-tests'>" +
521 "<div><p><a href='#'></a></p><code></code><pre></pre><span></span></div>" +
522 "<table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table>" +
523 "<ul><li></li></ul></div>"
524 ).appendTo( "#qunit-fixture" ).find( "*" ).css( "display", "none" );
534 "thead": "table-header-group",
535 "tbody": "table-row-group",
543 jQuery.each( test, function( selector, expected ) {
544 var elem = jQuery( selector, "#show-tests" ).show();
545 assert.equal( elem.css( "display" ), expected, "Show using correct display type for " + selector );
548 // Make sure that showing or hiding a text node doesn't cause an error
549 jQuery( "<div>test</div> text <span>test</span>" ).show().remove();
550 jQuery( "<div>test</div> text <span>test</span>" ).hide().remove();
553 QUnit.test( "show/hide detached nodes", function( assert ) {
558 div = jQuery( "<div>" ).hide();
559 assert.equal( div.css( "display" ), "none", "hide() updates inline style of a detached div" );
560 div.appendTo( "#qunit-fixture" );
561 assert.equal( div.css( "display" ), "none",
562 "A hidden-while-detached div is hidden after attachment" );
564 assert.equal( div.css( "display" ), "block",
565 "A hidden-while-detached div can be shown after attachment" );
567 div = jQuery( "<div class='hidden'>" );
568 div.show().appendTo( "#qunit-fixture" );
569 assert.equal( div.css( "display" ), "none",
570 "A shown-while-detached div can be hidden by the CSS cascade" );
572 div = jQuery( "<div><div class='hidden'></div></div>" ).children( "div" );
573 div.show().appendTo( "#qunit-fixture" );
574 assert.equal( div.css( "display" ), "none",
575 "A shown-while-detached div inside a visible div can be hidden by the CSS cascade" );
577 span = jQuery( "<span class='hidden'/>" );
578 span.show().appendTo( "#qunit-fixture" );
579 assert.equal( span.css( "display" ), "none",
580 "A shown-while-detached span can be hidden by the CSS cascade" );
582 div = jQuery( "div.hidden" );
584 assert.ok( !div[ 0 ].style.display,
585 "show() does not update inline style of a cascade-hidden-before-detach div" );
586 div.appendTo( "#qunit-fixture" );
587 assert.equal( div.css( "display" ), "none",
588 "A shown-while-detached cascade-hidden div is hidden after attachment" );
591 span = jQuery( "<span class='hidden'/>" );
592 span.appendTo( "#qunit-fixture" ).detach().show().appendTo( "#qunit-fixture" );
593 assert.equal( span.css( "display" ), "none",
594 "A shown-while-detached cascade-hidden span is hidden after attachment" );
597 div = jQuery( document.createElement( "div" ) );
598 div.show().appendTo( "#qunit-fixture" );
599 assert.ok( !div[ 0 ].style.display, "A shown-while-detached div has no inline style" );
600 assert.equal( div.css( "display" ), "block",
601 "A shown-while-detached div has default display after attachment" );
604 div = jQuery( "<div style='display: none'>" );
606 assert.equal( div[ 0 ].style.display, "",
607 "show() updates inline style of a detached inline-hidden div" );
608 div.appendTo( "#qunit-fixture" );
609 assert.equal( div.css( "display" ), "block",
610 "A shown-while-detached inline-hidden div has default display after attachment" );
612 div = jQuery( "<div><div style='display: none'></div></div>" ).children( "div" );
613 div.show().appendTo( "#qunit-fixture" );
614 assert.equal( div.css( "display" ), "block",
615 "A shown-while-detached inline-hidden div inside a visible div has default display " +
616 "after attachment" );
618 span = jQuery( "<span style='display: none'/>" );
620 assert.equal( span[ 0 ].style.display, "",
621 "show() updates inline style of a detached inline-hidden span" );
622 span.appendTo( "#qunit-fixture" );
623 assert.equal( span.css( "display" ), "inline",
624 "A shown-while-detached inline-hidden span has default display after attachment" );
626 div = jQuery( "<div style='display: inline'/>" );
627 div.show().appendTo( "#qunit-fixture" );
628 assert.equal( div.css( "display" ), "inline",
629 "show() does not update inline style of a detached inline-visible div" );
632 tr = jQuery( "<tr/>" );
633 jQuery( "#table" ).append( tr );
634 tr.detach().hide().show();
636 assert.ok( !tr[ 0 ].style.display, "Not-hidden detached tr elements have no inline style" );
639 span = jQuery( "<span/>" ).hide().show();
640 assert.ok( !span[ 0 ].style.display, "Not-hidden detached span elements have no inline style" );
644 QUnit.test( "hide hidden elements (bug #7141)", function( assert ) {
647 var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" );
648 assert.equal( div.css( "display" ), "none", "Element is hidden by default" );
650 assert.ok( !jQuery._data( div, "olddisplay" ), "olddisplay is undefined after hiding an already-hidden element" );
652 assert.equal( div.css( "display" ), "block", "Show a double-hidden element" );
657 QUnit.test( "show() after hide() should always set display to initial value (#14750)", function( assert ) {
660 var div = jQuery( "<div />" ),
661 fixture = jQuery( "#qunit-fixture" );
663 fixture.append( div );
665 div.css( "display", "inline" ).hide().show().css( "display", "list-item" ).hide().show();
666 assert.equal( div.css( "display" ), "list-item", "should get last set display value" );
669 QUnit.test( "show/hide 3.0, default display", function( assert ) {
674 $elems = jQuery( "<div/>" )
675 .appendTo( "#qunit-fixture" )
676 .html( "<div data-expected-display='block'/>" +
677 "<span data-expected-display='inline'/>" +
678 "<ul><li data-expected-display='list-item'/></ul>" )
679 .find( "[data-expected-display]" );
681 $elems.each( function() {
682 var $elem = jQuery( this ),
683 name = this.nodeName,
684 expected = this.getAttribute( "data-expected-display" ),
687 if ( this.className ) {
688 name += "." + this.className;
690 if ( this.getAttribute( "style" ) ) {
691 name += "[style='" + this.getAttribute( "style" ) + "']";
695 for ( i = 0; i < 3; i++ ) {
696 sequence.push( ".show()" );
698 assert.equal( $elem.css( "display" ), expected,
699 name + sequence.join( "" ) + " computed" );
700 assert.equal( this.style.display, "", name + sequence.join( "" ) + " inline" );
702 sequence.push( ".hide()" );
704 assert.equal( $elem.css( "display" ), "none",
705 name + sequence.join( "" ) + " computed" );
706 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
711 QUnit.test( "show/hide 3.0, default body display", function( assert ) {
715 var hideBody = supportjQuery( "<style>body{display:none}</style>" ).appendTo( document.head ),
716 body = jQuery( document.body );
718 assert.equal( body.css( "display" ), "none", "Correct initial display" );
722 assert.equal( body.css( "display" ), "block", "Correct display after .show()" );
727 QUnit.test( "show/hide 3.0, cascade display", function( assert ) {
732 $elems = jQuery( "<div/>" )
733 .appendTo( "#qunit-fixture" )
734 .html( "<span class='block'/><div class='inline'/><div class='list-item'/>" )
737 $elems.each( function() {
738 var $elem = jQuery( this ),
739 name = this.nodeName,
742 if ( this.className ) {
743 name += "." + this.className;
745 if ( this.getAttribute( "style" ) ) {
746 name += "[style='" + this.getAttribute( "style" ) + "']";
750 for ( i = 0; i < 3; i++ ) {
751 sequence.push( ".show()" );
753 assert.equal( $elem.css( "display" ), this.className,
754 name + sequence.join( "" ) + " computed" );
755 assert.equal( this.style.display, "", name + sequence.join( "" ) + " inline" );
757 sequence.push( ".hide()" );
759 assert.equal( $elem.css( "display" ), "none",
760 name + sequence.join( "" ) + " computed" );
761 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
766 QUnit.test( "show/hide 3.0, inline display", function( assert ) {
771 $elems = jQuery( "<div/>" )
772 .appendTo( "#qunit-fixture" )
773 .html( "<span data-expected-display='block' style='display:block'/>" +
774 "<span class='list-item' data-expected-display='block' style='display:block'/>" +
775 "<div data-expected-display='inline' style='display:inline'/>" +
776 "<div class='list-item' data-expected-display='inline' style='display:inline'/>" +
778 "<li data-expected-display='block' style='display:block'/>" +
779 "<li class='inline' data-expected-display='block' style='display:block'/>" +
780 "<li data-expected-display='inline' style='display:inline'/>" +
781 "<li class='block' data-expected-display='inline' style='display:inline'/>" +
783 .find( "[data-expected-display]" );
785 $elems.each( function() {
786 var $elem = jQuery( this ),
787 name = this.nodeName,
788 expected = this.getAttribute( "data-expected-display" ),
791 if ( this.className ) {
792 name += "." + this.className;
794 if ( this.getAttribute( "style" ) ) {
795 name += "[style='" + this.getAttribute( "style" ) + "']";
799 for ( i = 0; i < 3; i++ ) {
800 sequence.push( ".show()" );
802 assert.equal( $elem.css( "display" ), expected,
803 name + sequence.join( "" ) + " computed" );
804 assert.equal( this.style.display, expected, name + sequence.join( "" ) + " inline" );
806 sequence.push( ".hide()" );
808 assert.equal( $elem.css( "display" ), "none",
809 name + sequence.join( "" ) + " computed" );
810 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
815 QUnit.test( "show/hide 3.0, cascade hidden", function( assert ) {
820 $elems = jQuery( "<div/>" )
821 .appendTo( "#qunit-fixture" )
822 .html( "<div class='hidden' data-expected-display='block'/>" +
823 "<div class='hidden' data-expected-display='block' style='display:none'/>" +
824 "<span class='hidden' data-expected-display='inline'/>" +
825 "<span class='hidden' data-expected-display='inline' style='display:none'/>" +
827 "<li class='hidden' data-expected-display='list-item'/>" +
828 "<li class='hidden' data-expected-display='list-item' style='display:none'/>" +
830 .find( "[data-expected-display]" );
832 $elems.each( function() {
833 var $elem = jQuery( this ),
834 name = this.nodeName,
835 expected = this.getAttribute( "data-expected-display" ),
838 if ( this.className ) {
839 name += "." + this.className;
841 if ( this.getAttribute( "style" ) ) {
842 name += "[style='" + this.getAttribute( "style" ) + "']";
846 for ( i = 0; i < 3; i++ ) {
847 sequence.push( ".hide()" );
849 assert.equal( $elem.css( "display" ), "none",
850 name + sequence.join( "" ) + " computed" );
851 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
853 sequence.push( ".show()" );
855 assert.equal( $elem.css( "display" ), expected,
856 name + sequence.join( "" ) + " computed" );
857 assert.equal( this.style.display, expected, name + sequence.join( "" ) + " inline" );
862 QUnit.test( "show/hide 3.0, inline hidden", function( assert ) {
867 $elems = jQuery( "<div/>" )
868 .appendTo( "#qunit-fixture" )
869 .html( "<span data-expected-display='inline' style='display:none'/>" +
870 "<span class='list-item' data-expected-display='list-item' style='display:none'/>" +
871 "<div data-expected-display='block' style='display:none'/>" +
872 "<div class='list-item' data-expected-display='list-item' style='display:none'/>" +
874 "<li data-expected-display='list-item' style='display:none'/>" +
875 "<li class='block' data-expected-display='block' style='display:none'/>" +
876 "<li class='inline' data-expected-display='inline' style='display:none'/>" +
878 .find( "[data-expected-display]" );
880 $elems.each( function() {
881 var $elem = jQuery( this ),
882 name = this.nodeName,
883 expected = this.getAttribute( "data-expected-display" ),
886 if ( this.className ) {
887 name += "." + this.className;
889 if ( this.getAttribute( "style" ) ) {
890 name += "[style='" + this.getAttribute( "style" ) + "']";
894 for ( i = 0; i < 3; i++ ) {
895 sequence.push( ".hide()" );
897 assert.equal( $elem.css( "display" ), "none",
898 name + sequence.join( "" ) + " computed" );
899 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
901 sequence.push( ".show()" );
903 assert.equal( $elem.css( "display" ), expected,
904 name + sequence.join( "" ) + " computed" );
905 assert.equal( this.style.display, "", name + sequence.join( "" ) + " inline" );
912 QUnit[ jQuery.find.compile && jQuery.fn.toggle ? "test" : "skip" ]( "toggle()", function( assert ) {
915 x = jQuery( "#foo" );
917 assert.ok( x.is( ":visible" ), "is visible" );
919 assert.ok( x.is( ":hidden" ), "is hidden" );
921 assert.ok( x.is( ":visible" ), "is visible again" );
924 assert.ok( x.is( ":visible" ), "is visible" );
926 assert.ok( x.is( ":hidden" ), "is hidden" );
928 assert.ok( x.is( ":visible" ), "is visible again" );
930 div = jQuery( "<div style='display:none'><div></div></div>" ).appendTo( "#qunit-fixture" );
931 x = div.find( "div" );
932 assert.strictEqual( x.toggle().css( "display" ), "none", "is hidden" );
933 assert.strictEqual( x.toggle().css( "display" ), "block", "is visible" );
935 // Ensure hide() is called when toggled (#12148)
936 oldHide = jQuery.fn.hide;
937 jQuery.fn.hide = function() {
938 assert.ok( true, name + " method called on toggle" );
939 return oldHide.apply( this, arguments );
941 x.toggle( name === "show" );
942 jQuery.fn.hide = oldHide;
945 QUnit[ jQuery.find.compile && jQuery.fn.toggle ? "test" : "skip" ]( "detached toggle()", function( assert ) {
947 var detached = jQuery( "<p><a/><p>" ).find( "*" ).addBack(),
948 hiddenDetached = jQuery( "<p><a/></p>" ).find( "*" ).addBack().css( "display", "none" ),
949 cascadeHiddenDetached = jQuery( "<p><a/></p>" ).find( "*" ).addBack().addClass( "hidden" );
952 detached.appendTo( "#qunit-fixture" );
953 assert.equal( detached[ 0 ].style.display, "none", "detached element" );
954 assert.equal( detached[ 1 ].style.display, "none", "element in detached tree" );
956 hiddenDetached.toggle();
957 hiddenDetached.appendTo( "#qunit-fixture" );
958 assert.equal( hiddenDetached[ 0 ].style.display, "", "detached, hidden element" );
959 assert.equal( hiddenDetached[ 1 ].style.display, "", "hidden element in detached tree" );
961 cascadeHiddenDetached.toggle();
962 cascadeHiddenDetached.appendTo( "#qunit-fixture" );
963 assert.equal( cascadeHiddenDetached[ 0 ].style.display, "none",
964 "detached, cascade-hidden element" );
965 assert.equal( cascadeHiddenDetached[ 1 ].style.display, "none",
966 "cascade-hidden element in detached tree" );
969 QUnit.test( "jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function( assert ) {
972 var $checkedtest = jQuery( "#checkedtest" );
973 jQuery.css( $checkedtest[ 0 ], "height" );
975 assert.ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." );
976 assert.ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." );
977 assert.ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." );
978 assert.ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." );
981 QUnit.test( "internal ref to elem.runtimeStyle (bug #7608)", function( assert ) {
986 jQuery( "#foo" ).css( { "width": "0%" } ).css( "width" );
991 assert.ok( result, "elem.runtimeStyle does not throw exception" );
994 QUnit.test( "computed margins (trac-3333; gh-2237)", function( assert ) {
997 var $div = jQuery( "#foo" ),
998 $child = jQuery( "#en" );
1004 assert.equal( $div.css( "marginRight" ), "0px",
1005 "marginRight correctly calculated with a width and display block" );
1008 position: "absolute",
1017 assert.equal( $child.css( "marginLeft" ), "25px", "auto margins are computed to pixels" );
1020 QUnit.test( "box model properties incorrectly returning % instead of px, see #10639 and #12088", function( assert ) {
1023 var container = jQuery( "<div/>" ).width( 400 ).appendTo( "#qunit-fixture" ),
1024 el = jQuery( "<div/>" ).css( { "width": "50%", "marginRight": "50%" } ).appendTo( container ),
1025 el2 = jQuery( "<div/>" ).css( { "width": "50%", "minWidth": "300px", "marginLeft": "25%" } ).appendTo( container );
1027 assert.equal( el.css( "marginRight" ), "200px", "css('marginRight') returning % instead of px, see #10639" );
1028 assert.equal( el2.css( "marginLeft" ), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" );
1031 QUnit.test( "jQuery.cssProps behavior, (bug #8402)", function( assert ) {
1034 var div = jQuery( "<div>" ).appendTo( document.body ).css( {
1035 "position": "absolute",
1039 jQuery.cssProps.top = "left";
1040 assert.equal( div.css( "top" ), "10px", "the fixed property is used when accessing the computed style" );
1041 div.css( "top", "100px" );
1042 assert.equal( div[ 0 ].style.left, "100px", "the fixed property is used when setting the style" );
1044 // cleanup jQuery.cssProps
1045 jQuery.cssProps.top = undefined;
1048 QUnit.test( "widows & orphans #8936", function( assert ) {
1050 var $p = jQuery( "<p>" ).appendTo( "#qunit-fixture" );
1059 assert.equal( $p.css( "widows" ) || jQuery.style( $p[ 0 ], "widows" ), 3, "widows correctly set to 3" );
1060 assert.equal( $p.css( "orphans" ) || jQuery.style( $p[ 0 ], "orphans" ), 3, "orphans correctly set to 3" );
1065 QUnit.test( "can't get css for disconnected in IE<9, see #10254 and #8388", function( assert ) {
1069 span = jQuery( "<span/>" ).css( "background-image", "url(" + baseURL + "1x1.jpg)" );
1070 assert.notEqual( span.css( "background-image" ), null, "can't get background-image in IE<9, see #10254" );
1072 div = jQuery( "<div/>" ).css( "top", 10 );
1073 assert.equal( div.css( "top" ), "10px", "can't get top in IE<9, see #8388" );
1076 QUnit.test( "Ensure styles are retrieving from parsed html on document fragments", function( assert ) {
1080 jQuery.parseHTML( "<span style=\"font-family: Cuprum,sans-serif; font-size: 14px; color: #999999;\">some text</span>" )
1083 assert.equal( $span.css( "font-size" ), "14px", "Font-size retrievable on parsed HTML node" );
1086 QUnit.test( "can't get background-position in IE<9, see #10796", function( assert ) {
1087 var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ),
1103 for ( ; i < l; i++ ) {
1104 div.css( "background-position", units [ i ] );
1105 assert.ok( div.css( "background-position" ), "can't get background-position in IE<9, see #10796" );
1109 if ( jQuery.fn.offset ) {
1110 QUnit.test( "percentage properties for left and top should be transformed to pixels, see #9505", function( assert ) {
1112 var parent = jQuery( "<div style='position:relative;width:200px;height:200px;margin:0;padding:0;border-width:0'></div>" ).appendTo( "#qunit-fixture" ),
1113 div = jQuery( "<div style='position: absolute; width: 20px; height: 20px; top:50%; left:50%'></div>" ).appendTo( parent );
1115 assert.equal( div.css( "top" ), "100px", "position properties not transformed to pixels, see #9505" );
1116 assert.equal( div.css( "left" ), "100px", "position properties not transformed to pixels, see #9505" );
1120 QUnit.test( "Do not append px (#9548, #12990, #2792)", function( assert ) {
1123 var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
1125 $div.css( "fill-opacity", 1 );
1127 assert.equal( $div.css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
1129 $div.css( "column-count", 1 );
1130 if ( $div.css( "column-count" ) !== undefined ) {
1131 assert.equal( $div.css( "column-count" ), 1, "Do not append px to 'column-count'" );
1133 assert.ok( true, "No support for column-count CSS property" );
1136 $div.css( "animation-iteration-count", 2 );
1137 if ( $div.css( "animation-iteration-count" ) !== undefined ) {
1138 // if $div.css( "animation-iteration-count" ) return "1",
1139 // it actually return the default value of animation-iteration-count
1140 assert.equal( $div.css( "animation-iteration-count" ), 2, "Do not append px to 'animation-iteration-count'" );
1142 assert.ok( true, "No support for animation-iteration-count CSS property" );
1146 QUnit.test( "css('width') and css('height') should respect box-sizing, see #11004", function( assert ) {
1149 var el_dis = jQuery( "<div style='width:300px;height:300px;margin:2px;padding:2px;box-sizing:border-box;'>test</div>" ),
1150 el = el_dis.clone().appendTo( "#qunit-fixture" );
1152 assert.equal( el.css( "width" ), el.css( "width", el.css( "width" ) ).css( "width" ), "css('width') is not respecting box-sizing, see #11004" );
1153 assert.equal( el_dis.css( "width" ), el_dis.css( "width", el_dis.css( "width" ) ).css( "width" ), "css('width') is not respecting box-sizing for disconnected element, see #11004" );
1154 assert.equal( el.css( "height" ), el.css( "height", el.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing, see #11004" );
1155 assert.equal( el_dis.css( "height" ), el_dis.css( "height", el_dis.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing for disconnected element, see #11004" );
1159 "css('width') should work correctly before document ready (#14084)",
1160 "css/cssWidthBeforeDocReady.html",
1161 function( assert, jQuery, window, document, cssWidthBeforeDocReady ) {
1163 assert.strictEqual( cssWidthBeforeDocReady, "100px", "elem.css('width') works correctly before document ready" );
1168 "css('width') should work correctly with browser zooming",
1169 "css/cssWidthBrowserZoom.html",
1170 function( assert, jQuery, window, document, cssWidthBrowserZoom ) {
1172 assert.strictEqual( cssWidthBrowserZoom, "100px", "elem.css('width') works correctly with browser zoom" );
1177 var supportsFractionalGBCR,
1178 qunitFixture = document.getElementById( "qunit-fixture" ),
1179 div = document.createElement( "div" );
1180 div.style.width = "3.3px";
1181 qunitFixture.appendChild( div );
1182 supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed( 1 ) === "3.3";
1183 qunitFixture.removeChild( div );
1185 QUnit.test( "css('width') and css('height') should return fractional values for nodes in the document", function( assert ) {
1186 if ( !supportsFractionalGBCR ) {
1188 assert.ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
1194 var el = jQuery( "<div class='test-div'></div>" ).appendTo( "#qunit-fixture" );
1195 jQuery( "<style>.test-div { width: 33.3px; height: 88.8px; }</style>" ).appendTo( "#qunit-fixture" );
1197 assert.equal( Number( el.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
1198 "css('width') should return fractional values" );
1199 assert.equal( Number( el.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
1200 "css('height') should return fractional values" );
1203 QUnit.test( "css('width') and css('height') should return fractional values for disconnected nodes", function( assert ) {
1204 if ( !supportsFractionalGBCR ) {
1206 assert.ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
1212 var el = jQuery( "<div style='width: 33.3px; height: 88.8px;'></div>" );
1214 assert.equal( Number( el.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
1215 "css('width') should return fractional values" );
1216 assert.equal( Number( el.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
1217 "css('height') should return fractional values" );
1221 QUnit.test( "certain css values of 'normal' should be convertable to a number, see #8627", function( assert ) {
1224 var el = jQuery( "<div style='letter-spacing:normal;font-weight:normal;'>test</div>" ).appendTo( "#qunit-fixture" );
1226 assert.ok( !isNaN( parseFloat( el.css( "letterSpacing" ) ) ), "css('letterSpacing') not convertable to number, see #8627" );
1227 assert.ok( !isNaN( parseFloat( el.css( "fontWeight" ) ) ), "css('fontWeight') not convertable to number, see #8627" );
1228 assert.equal( typeof el.css( "fontWeight" ), "string", ".css() returns a string" );
1231 // Support: IE 9 only
1232 // Only run this test in IE9
1233 if ( document.documentMode === 9 ) {
1234 QUnit.test( ".css('filter') returns a string in IE9, see #12537", function( assert ) {
1237 assert.equal( jQuery( "<div style='-ms-filter:\"progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)\";'></div>" ).css( "filter" ), "progid:DXImageTransform.Microsoft.gradient(startColorstr=#FFFFFF, endColorstr=#ECECEC)", "IE9 returns the correct value from css('filter')." );
1241 QUnit.test( "cssHooks - expand", function( assert ) {
1242 assert.expect( 15 );
1245 margin: [ "marginTop", "marginRight", "marginBottom", "marginLeft" ],
1246 borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth" ],
1247 padding: [ "paddingTop", "paddingRight", "paddingBottom", "paddingLeft" ]
1250 jQuery.each( properties, function( property, keys ) {
1251 var hook = jQuery.cssHooks[ property ],
1253 jQuery.each( keys, function( _, key ) {
1254 expected[ key ] = 10;
1256 result = hook.expand( 10 );
1257 assert.deepEqual( result, expected, property + " expands properly with a number" );
1259 jQuery.each( keys, function( _, key ) {
1260 expected[ key ] = "10px";
1262 result = hook.expand( "10px" );
1263 assert.deepEqual( result, expected, property + " expands properly with '10px'" );
1265 expected[ keys[ 1 ] ] = expected[ keys[ 3 ] ] = "20px";
1266 result = hook.expand( "10px 20px" );
1267 assert.deepEqual( result, expected, property + " expands properly with '10px 20px'" );
1269 expected[ keys[ 2 ] ] = "30px";
1270 result = hook.expand( "10px 20px 30px" );
1271 assert.deepEqual( result, expected, property + " expands properly with '10px 20px 30px'" );
1273 expected[ keys[ 3 ] ] = "40px";
1274 result = hook.expand( "10px 20px 30px 40px" );
1275 assert.deepEqual( result, expected, property + " expands properly with '10px 20px 30px 40px'" );
1281 QUnit.test( "css opacity consistency across browsers (#12685)", function( assert ) {
1285 fixture = jQuery( "#qunit-fixture" );
1287 // Append style element
1288 jQuery( "<style>.opacity_t12685 { opacity: 0.1; }</style>" ).appendTo( fixture );
1290 el = jQuery( "<div class='opacity_t12685'></div>" ).appendTo( fixture );
1292 assert.equal( Math.round( el.css( "opacity" ) * 100 ), 10, "opacity from style sheet" );
1293 el.css( "opacity", 0.3 );
1294 assert.equal( Math.round( el.css( "opacity" ) * 100 ), 30, "override opacity" );
1295 el.css( "opacity", "" );
1296 assert.equal( Math.round( el.css( "opacity" ) * 100 ), 10, "remove opacity override" );
1299 QUnit[ jQuery.find.compile ? "test" : "skip" ]( ":visible/:hidden selectors", function( assert ) {
1300 assert.expect( 17 );
1302 var $div, $table, $a;
1304 assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
1305 jQuery( "#nothiddendiv" ).css( { display: "none" } );
1306 assert.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
1307 jQuery( "#nothiddendiv" ).css( { "display": "block" } );
1308 assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
1309 assert.ok( !jQuery( window ).is( ":visible" ), "Calling is(':visible') on window does not throw an exception (#10267)." );
1310 assert.ok( !jQuery( document ).is( ":visible" ), "Calling is(':visible') on document does not throw an exception (#10267)." );
1312 assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
1313 jQuery( "#nothiddendiv" ).css( "display", "none" );
1314 assert.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
1315 jQuery( "#nothiddendiv" ).css( "display", "block" );
1316 assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
1318 assert.ok( jQuery( "#siblingspan" ).is( ":visible" ), "Span with no content is visible" );
1319 $div = jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" );
1320 assert.equal( $div.find( ":visible" ).length, 1, "Span with no content is visible" );
1321 $div.css( { width: 0, height: 0, overflow: "hidden" } );
1322 assert.ok( $div.is( ":visible" ), "Div with width and height of 0 is still visible (gh-2227)" );
1324 // Safari 6-7 and iOS 6-7 report 0 width for br elements
1325 // When newer browsers propagate, re-enable this test
1326 // $br = jQuery( "<br/>" ).appendTo( "#qunit-fixture" );
1327 // ok( $br.is( ":visible" ), "br element is visible" );
1329 $table = jQuery( "#table" );
1330 $table.html( "<tr><td style='display:none'>cell</td><td>cell</td></tr>" );
1331 assert.equal( jQuery( "#table td:visible" ).length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements" );
1332 $table.css( "display", "none" ).html( "<tr><td>cell</td><td>cell</td></tr>" );
1333 assert.equal( jQuery( "#table td:visible" ).length, 0, "hidden cell children not perceived as visible (#4512)" );
1335 assert.t( "Is Visible", "#qunit-fixture div:visible:lt(2)", [ "foo", "nothiddendiv" ] );
1336 assert.t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
1337 assert.t( "Is Hidden", "#form input:hidden", [ "hidden1", "hidden2" ] );
1339 $a = jQuery( "<a href='#'><h1>Header</h1></a>" ).appendTo( "#qunit-fixture" );
1340 assert.ok( $a.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" );
1343 QUnit.test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function( assert ) {
1346 var el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", "fake value" );
1347 assert.equal( el.css( "position" ), "absolute", "The old style is kept when setting an unrecognized value" );
1350 // Support: Edge 14 - 15
1351 // Edge collapses whitespace-only values when setting a style property and
1352 // there is no easy way for us to work around it. Just skip the test there
1353 // and hope for the better future.
1354 QUnit[ /\bedge\//i.test( navigator.userAgent ) ? "skip" : "test" ](
1355 "Keep the last style if the new one is a non-empty whitespace (gh-3204)",
1356 function( assert ) {
1359 var el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", " " );
1360 assert.equal( el.css( "position" ), "absolute", "The old style is kept when setting to a space" );
1363 QUnit.test( "Reset the style if set to an empty string", function( assert ) {
1365 var el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", "" );
1367 // Some browsers return an empty string; others "static". Both those cases mean the style
1368 // was reset successfully so accept them both.
1369 assert.equal( el.css( "position" ) || "static", "static",
1370 "The style can be reset by setting to an empty string" );
1374 "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)",
1376 function( assert ) {
1377 var done = assert.async();
1379 name: "backgroundAttachment",
1381 expected: [ "scroll" ]
1383 name: "backgroundColor",
1384 value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
1385 expected: [ "transparent" ]
1388 // Firefox returns auto's value
1389 name: "backgroundImage",
1390 value: [ "url('test.png')", "url(" + baseURL + "test.png)", "url(\"" + baseURL + "test.png\")" ],
1391 expected: [ "none", "url(\"http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif\")" ]
1393 name: "backgroundPosition",
1395 expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ]
1398 // Firefox returns no-repeat
1399 name: "backgroundRepeat",
1400 value: [ "repeat-y" ],
1401 expected: [ "repeat", "no-repeat" ]
1403 name: "backgroundClip",
1404 value: [ "padding-box" ],
1405 expected: [ "border-box" ]
1407 name: "backgroundOrigin",
1408 value: [ "content-box" ],
1409 expected: [ "padding-box" ]
1411 name: "backgroundSize",
1412 value: [ "80px 60px" ],
1413 expected: [ "auto auto" ]
1416 jQuery.each( styles, function( index, style ) {
1417 var $clone, $clonedChildren,
1418 $source = jQuery( "#firstp" ),
1419 source = $source[ 0 ],
1420 $children = $source.children();
1422 style.expected = style.expected.concat( [ "", "auto" ] );
1424 if ( source.style[ style.name ] === undefined ) {
1425 assert.ok( true, style.name + ": style isn't supported and therefore not an issue" );
1431 $source.css( style.name, style.value[ 0 ] );
1432 $children.css( style.name, style.value[ 0 ] );
1434 $clone = $source.clone();
1435 $clonedChildren = $clone.children();
1437 $clone.css( style.name, "" );
1438 $clonedChildren.css( style.name, "" );
1440 window.setTimeout( function() {
1441 assert.notEqual( $clone.css( style.name ), style.value[ 0 ], "Cloned css was changed" );
1443 assert.ok( jQuery.inArray( $source.css( style.name ) !== -1, style.value ),
1444 "Clearing clone.css() doesn't affect source.css(): " + style.name +
1445 "; result: " + $source.css( style.name ) +
1446 "; expected: " + style.value.join( "," ) );
1448 assert.ok( jQuery.inArray( $children.css( style.name ) !== -1, style.value ),
1449 "Clearing clonedChildren.css() doesn't affect children.css(): " + style.name +
1450 "; result: " + $children.css( style.name ) +
1451 "; expected: " + style.value.join( "," ) );
1455 window.setTimeout( done, 1000 );
1459 // Support: IE <=10 only
1460 // We have to jump through the hoops here in order to test work with "order" CSS property,
1461 // that some browsers do not support. This test is not, strictly speaking, correct,
1462 // but it's the best that we can do.
1464 var style = document.createElement( "div" ).style,
1465 exist = "order" in style || "WebkitOrder" in style;
1468 QUnit.test( "Don't append px to CSS \"order\" value (#14049)", function( assert ) {
1471 var $elem = jQuery( "<div/>" );
1473 $elem.css( "order", 2 );
1474 assert.equal( $elem.css( "order" ), "2", "2 on order" );
1479 QUnit.test( "Do not throw on frame elements from css method (#15098)", function( assert ) {
1482 var frameWin, frameDoc,
1483 frameElement = document.createElement( "iframe" ),
1484 frameWrapDiv = document.createElement( "div" );
1486 frameWrapDiv.appendChild( frameElement );
1487 document.body.appendChild( frameWrapDiv );
1488 frameWin = frameElement.contentWindow;
1489 frameDoc = frameWin.document;
1491 frameDoc.write( "<!doctype html><html><body><div>Hi</div></body></html>" );
1494 frameWrapDiv.style.display = "none";
1497 jQuery( frameDoc.body ).css( "direction" );
1498 assert.ok( true, "It didn't throw" );
1500 assert.ok( false, "It did throw" );
1505 var vendorPrefixes = [ "Webkit", "Moz", "ms" ];
1507 function resetCssPropsFor( name ) {
1508 delete jQuery.cssProps[ name ];
1509 jQuery.each( vendorPrefixes, function( index, prefix ) {
1510 delete jQuery.cssProps[ prefix + name[ 0 ].toUpperCase() + name.slice( 1 ) ];
1514 QUnit.test( "Don't default to a cached previously used wrong prefixed name (gh-2015)", function( assert ) {
1516 // Note: this test needs a property we know is only supported in a prefixed version
1517 // by at least one of our main supported browsers. This may get out of date so let's
1518 // use -(webkit|moz)-appearance as well as those two are not on a standards track.
1519 var appearanceName, transformName, elem, elemStyle,
1520 transformVal = "translate(5px, 2px)",
1521 emptyStyle = document.createElement( "div" ).style;
1523 if ( "appearance" in emptyStyle ) {
1524 appearanceName = "appearance";
1526 jQuery.each( vendorPrefixes, function( index, prefix ) {
1527 var prefixedProp = prefix + "Appearance";
1528 if ( prefixedProp in emptyStyle ) {
1529 appearanceName = prefixedProp;
1534 if ( "transform" in emptyStyle ) {
1535 transformName = "transform";
1537 jQuery.each( vendorPrefixes, function( index, prefix ) {
1538 var prefixedProp = prefix + "Transform";
1539 if ( prefixedProp in emptyStyle ) {
1540 transformName = prefixedProp;
1545 assert.expect( !!appearanceName + !!transformName + 1 );
1547 resetCssPropsFor( "appearance" );
1548 resetCssPropsFor( "transform" );
1550 elem = jQuery( "<div/>" )
1552 msAppearance: "none",
1555 // Only the ms prefix is used to make sure we haven't e.g. set
1556 // webkitTransform ourselves in the test.
1557 msTransform: transformVal,
1558 transform: transformVal
1560 elemStyle = elem[ 0 ].style;
1562 if ( appearanceName ) {
1563 assert.equal( elemStyle[ appearanceName ], "none", "setting properly-prefixed appearance" );
1565 if ( transformName ) {
1566 assert.equal( elemStyle[ transformName ], transformVal, "setting properly-prefixed transform" );
1568 assert.equal( elemStyle[ "undefined" ], undefined, "Nothing writes to node.style.undefined" );
1571 QUnit.test( "Don't detect fake set properties on a node when caching the prefixed version", function( assert ) {
1574 var elem = jQuery( "<div/>" ),
1575 style = elem[ 0 ].style;
1576 style.MozFakeProperty = "old value";
1577 elem.css( "fakeProperty", "new value" );
1579 assert.equal( style.MozFakeProperty, "old value", "Fake prefixed property is not cached" );
1585 var supportsCssVars,
1586 elem = jQuery( "<div>" ).appendTo( document.body ),
1589 div.style.setProperty( "--prop", "value" );
1590 supportsCssVars = !!getComputedStyle( div ).getPropertyValue( "--prop" );
1593 QUnit[ supportsCssVars ? "test" : "skip" ]( "css(--customProperty)", function( assert ) {
1594 jQuery( "#qunit-fixture" ).append(
1596 " .test__customProperties {\n" +
1597 " --prop1:val1;\n" +
1598 " --prop2: val2;\n" +
1599 " --prop3:val3 ;\n" +
1600 " --prop4:\"val4\";\n" +
1601 " --prop5:'val5';\n" +
1606 var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
1607 $elem = jQuery( "<div>" ).addClass( "test__customProperties" )
1608 .appendTo( "#qunit-fixture" ),
1609 webkit = /\bsafari\b/i.test( navigator.userAgent ) &&
1610 !/\firefox\b/i.test( navigator.userAgent ) &&
1611 !/\edge\b/i.test( navigator.userAgent ),
1612 oldSafari = webkit && ( /\b9\.\d(\.\d+)* safari/i.test( navigator.userAgent ) ||
1613 /\b10\.0(\.\d+)* safari/i.test( navigator.userAgent ) ||
1614 /iphone os (?:9|10)_/i.test( navigator.userAgent ) ),
1623 assert.expect( expected );
1625 div.css( "--color", "blue" );
1626 assert.equal( div.css( "--color" ), "blue", "Modified CSS custom property using string" );
1628 div.css( "--color", "yellow" );
1629 assert.equal( div.css( "--color" ), "yellow", "Overwrite CSS custom property" );
1631 div.css( { "--color": "red" } );
1632 assert.equal( div.css( "--color" ), "red", "Modified CSS custom property using object" );
1634 div.css( { "--mixedCase": "green" } );
1635 assert.equal( div.css( "--mixedCase" ), "green",
1636 "Modified CSS custom property with mixed case" );
1638 div.css( { "--theme-dark": "purple" } );
1639 assert.equal( div.css( "--theme-dark" ), "purple",
1640 "Modified CSS custom property with dashed name" );
1642 assert.equal( $elem.css( "--prop1" ), "val1", "Basic CSS custom property" );
1644 // Support: Safari 9.1-10.0 only
1645 // Safari collapses whitespaces & quotes. Ignore it.
1647 assert.equal( $elem.css( "--prop2" ), " val2", "Preceding whitespace maintained" );
1648 assert.equal( $elem.css( "--prop3" ), "val3 ", "Following whitespace maintained" );
1651 // Support: Chrome 49-55, Safari 9.1-10.0
1652 // Chrome treats single quotes as double ones.
1653 // Safari treats double quotes as single ones.
1655 assert.equal( $elem.css( "--prop4" ), "\"val4\"", "Works with double quotes" );
1656 assert.equal( $elem.css( "--prop5" ), "'val5'", "Works with single quotes" );