3 QUnit.module( "css", { afterEach: 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[ document.body.attachShadow ? "test" : "skip" ]( "show/hide shadow child nodes", function( assert ) {
646 jQuery( "<div id='shadowHost'></div>" ).appendTo( "#qunit-fixture" );
647 var shadowHost = document.querySelector( "#shadowHost" );
648 var shadowRoot = shadowHost.attachShadow( { mode: "open" } );
649 shadowRoot.innerHTML = "" +
650 "<style>.hidden{display: none;}</style>" +
651 "<div class='hidden' id='shadowdiv'>" +
652 " <p class='hidden' id='shadowp'>" +
653 " <a href='#' class='hidden' id='shadowa'></a>" +
655 " <code class='hidden' id='shadowcode'></code>" +
656 " <pre class='hidden' id='shadowpre'></pre>" +
657 " <span class='hidden' id='shadowspan'></span>" +
659 "<table class='hidden' id='shadowtable'>" +
660 " <thead class='hidden' id='shadowthead'>" +
661 " <tr class='hidden' id='shadowtr'>" +
662 " <th class='hidden' id='shadowth'></th>" +
665 " <tbody class='hidden' id='shadowtbody'>" +
666 " <tr class='hidden'>" +
667 " <td class='hidden' id='shadowtd'></td>" +
671 "<ul class='hidden' id='shadowul'>" +
672 " <li class='hidden' id='shadowli'></li>" +
683 "thead": "table-header-group",
684 "tbody": "table-row-group",
692 jQuery.each( test, function( selector, expected ) {
693 var shadowChild = shadowRoot.querySelector( "#shadow" + selector );
694 var $shadowChild = jQuery( shadowChild );
695 assert.strictEqual( $shadowChild.css( "display" ), "none", "is hidden" );
697 assert.strictEqual( $shadowChild.css( "display" ), expected, "Show using correct display type for " + selector );
701 QUnit.test( "hide hidden elements (bug #7141)", function( assert ) {
704 var div = jQuery( "<div style='display:none'></div>" ).appendTo( "#qunit-fixture" );
705 assert.equal( div.css( "display" ), "none", "Element is hidden by default" );
707 assert.ok( !jQuery._data( div, "olddisplay" ), "olddisplay is undefined after hiding an already-hidden element" );
709 assert.equal( div.css( "display" ), "block", "Show a double-hidden element" );
714 QUnit.test( "show() after hide() should always set display to initial value (#14750)", function( assert ) {
717 var div = jQuery( "<div />" ),
718 fixture = jQuery( "#qunit-fixture" );
720 fixture.append( div );
722 div.css( "display", "inline" ).hide().show().css( "display", "list-item" ).hide().show();
723 assert.equal( div.css( "display" ), "list-item", "should get last set display value" );
726 QUnit.test( "show/hide 3.0, default display", function( assert ) {
731 $elems = jQuery( "<div/>" )
732 .appendTo( "#qunit-fixture" )
733 .html( "<div data-expected-display='block'/>" +
734 "<span data-expected-display='inline'/>" +
735 "<ul><li data-expected-display='list-item'/></ul>" )
736 .find( "[data-expected-display]" );
738 $elems.each( function() {
739 var $elem = jQuery( this ),
740 name = this.nodeName,
741 expected = this.getAttribute( "data-expected-display" ),
744 if ( this.className ) {
745 name += "." + this.className;
747 if ( this.getAttribute( "style" ) ) {
748 name += "[style='" + this.getAttribute( "style" ) + "']";
752 for ( i = 0; i < 3; i++ ) {
753 sequence.push( ".show()" );
755 assert.equal( $elem.css( "display" ), expected,
756 name + sequence.join( "" ) + " computed" );
757 assert.equal( this.style.display, "", name + sequence.join( "" ) + " inline" );
759 sequence.push( ".hide()" );
761 assert.equal( $elem.css( "display" ), "none",
762 name + sequence.join( "" ) + " computed" );
763 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
768 QUnit.test( "show/hide 3.0, default body display", function( assert ) {
772 var hideBody = supportjQuery( "<style>body{display:none}</style>" ).appendTo( document.head ),
773 body = jQuery( document.body );
775 assert.equal( body.css( "display" ), "none", "Correct initial display" );
779 assert.equal( body.css( "display" ), "block", "Correct display after .show()" );
784 QUnit.test( "show/hide 3.0, cascade display", function( assert ) {
789 $elems = jQuery( "<div/>" )
790 .appendTo( "#qunit-fixture" )
791 .html( "<span class='block'/><div class='inline'/><div class='list-item'/>" )
794 $elems.each( function() {
795 var $elem = jQuery( this ),
796 name = this.nodeName,
799 if ( this.className ) {
800 name += "." + this.className;
802 if ( this.getAttribute( "style" ) ) {
803 name += "[style='" + this.getAttribute( "style" ) + "']";
807 for ( i = 0; i < 3; i++ ) {
808 sequence.push( ".show()" );
810 assert.equal( $elem.css( "display" ), this.className,
811 name + sequence.join( "" ) + " computed" );
812 assert.equal( this.style.display, "", name + sequence.join( "" ) + " inline" );
814 sequence.push( ".hide()" );
816 assert.equal( $elem.css( "display" ), "none",
817 name + sequence.join( "" ) + " computed" );
818 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
823 QUnit.test( "show/hide 3.0, inline display", function( assert ) {
828 $elems = jQuery( "<div/>" )
829 .appendTo( "#qunit-fixture" )
830 .html( "<span data-expected-display='block' style='display:block'/>" +
831 "<span class='list-item' data-expected-display='block' style='display:block'/>" +
832 "<div data-expected-display='inline' style='display:inline'/>" +
833 "<div class='list-item' data-expected-display='inline' style='display:inline'/>" +
835 "<li data-expected-display='block' style='display:block'/>" +
836 "<li class='inline' data-expected-display='block' style='display:block'/>" +
837 "<li data-expected-display='inline' style='display:inline'/>" +
838 "<li class='block' data-expected-display='inline' style='display:inline'/>" +
840 .find( "[data-expected-display]" );
842 $elems.each( function() {
843 var $elem = jQuery( this ),
844 name = this.nodeName,
845 expected = this.getAttribute( "data-expected-display" ),
848 if ( this.className ) {
849 name += "." + this.className;
851 if ( this.getAttribute( "style" ) ) {
852 name += "[style='" + this.getAttribute( "style" ) + "']";
856 for ( i = 0; i < 3; i++ ) {
857 sequence.push( ".show()" );
859 assert.equal( $elem.css( "display" ), expected,
860 name + sequence.join( "" ) + " computed" );
861 assert.equal( this.style.display, expected, name + sequence.join( "" ) + " inline" );
863 sequence.push( ".hide()" );
865 assert.equal( $elem.css( "display" ), "none",
866 name + sequence.join( "" ) + " computed" );
867 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
872 QUnit.test( "show/hide 3.0, cascade hidden", function( assert ) {
877 $elems = jQuery( "<div/>" )
878 .appendTo( "#qunit-fixture" )
879 .html( "<div class='hidden' data-expected-display='block'/>" +
880 "<div class='hidden' data-expected-display='block' style='display:none'/>" +
881 "<span class='hidden' data-expected-display='inline'/>" +
882 "<span class='hidden' data-expected-display='inline' style='display:none'/>" +
884 "<li class='hidden' data-expected-display='list-item'/>" +
885 "<li class='hidden' data-expected-display='list-item' style='display:none'/>" +
887 .find( "[data-expected-display]" );
889 $elems.each( function() {
890 var $elem = jQuery( this ),
891 name = this.nodeName,
892 expected = this.getAttribute( "data-expected-display" ),
895 if ( this.className ) {
896 name += "." + this.className;
898 if ( this.getAttribute( "style" ) ) {
899 name += "[style='" + this.getAttribute( "style" ) + "']";
903 for ( i = 0; i < 3; i++ ) {
904 sequence.push( ".hide()" );
906 assert.equal( $elem.css( "display" ), "none",
907 name + sequence.join( "" ) + " computed" );
908 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
910 sequence.push( ".show()" );
912 assert.equal( $elem.css( "display" ), expected,
913 name + sequence.join( "" ) + " computed" );
914 assert.equal( this.style.display, expected, name + sequence.join( "" ) + " inline" );
919 QUnit.test( "show/hide 3.0, inline hidden", function( assert ) {
924 $elems = jQuery( "<div/>" )
925 .appendTo( "#qunit-fixture" )
926 .html( "<span data-expected-display='inline' style='display:none'/>" +
927 "<span class='list-item' data-expected-display='list-item' style='display:none'/>" +
928 "<div data-expected-display='block' style='display:none'/>" +
929 "<div class='list-item' data-expected-display='list-item' style='display:none'/>" +
931 "<li data-expected-display='list-item' style='display:none'/>" +
932 "<li class='block' data-expected-display='block' style='display:none'/>" +
933 "<li class='inline' data-expected-display='inline' style='display:none'/>" +
935 .find( "[data-expected-display]" );
937 $elems.each( function() {
938 var $elem = jQuery( this ),
939 name = this.nodeName,
940 expected = this.getAttribute( "data-expected-display" ),
943 if ( this.className ) {
944 name += "." + this.className;
946 if ( this.getAttribute( "style" ) ) {
947 name += "[style='" + this.getAttribute( "style" ) + "']";
951 for ( i = 0; i < 3; i++ ) {
952 sequence.push( ".hide()" );
954 assert.equal( $elem.css( "display" ), "none",
955 name + sequence.join( "" ) + " computed" );
956 assert.equal( this.style.display, "none", name + sequence.join( "" ) + " inline" );
958 sequence.push( ".show()" );
960 assert.equal( $elem.css( "display" ), expected,
961 name + sequence.join( "" ) + " computed" );
962 assert.equal( this.style.display, "", name + sequence.join( "" ) + " inline" );
969 QUnit[ jQuery.find.compile && jQuery.fn.toggle ? "test" : "skip" ]( "toggle()", function( assert ) {
972 x = jQuery( "#foo" );
974 assert.ok( x.is( ":visible" ), "is visible" );
976 assert.ok( x.is( ":hidden" ), "is hidden" );
978 assert.ok( x.is( ":visible" ), "is visible again" );
981 assert.ok( x.is( ":visible" ), "is visible" );
983 assert.ok( x.is( ":hidden" ), "is hidden" );
985 assert.ok( x.is( ":visible" ), "is visible again" );
987 div = jQuery( "<div style='display:none'><div></div></div>" ).appendTo( "#qunit-fixture" );
988 x = div.find( "div" );
989 assert.strictEqual( x.toggle().css( "display" ), "none", "is hidden" );
990 assert.strictEqual( x.toggle().css( "display" ), "block", "is visible" );
992 // Ensure hide() is called when toggled (#12148)
993 oldHide = jQuery.fn.hide;
994 jQuery.fn.hide = function() {
995 assert.ok( true, name + " method called on toggle" );
996 return oldHide.apply( this, arguments );
998 x.toggle( name === "show" );
999 jQuery.fn.hide = oldHide;
1002 QUnit[ jQuery.find.compile && jQuery.fn.toggle ? "test" : "skip" ]( "detached toggle()", function( assert ) {
1004 var detached = jQuery( "<p><a/><p>" ).find( "*" ).addBack(),
1005 hiddenDetached = jQuery( "<p><a/></p>" ).find( "*" ).addBack().css( "display", "none" ),
1006 cascadeHiddenDetached = jQuery( "<p><a/></p>" ).find( "*" ).addBack().addClass( "hidden" );
1009 detached.appendTo( "#qunit-fixture" );
1010 assert.equal( detached[ 0 ].style.display, "none", "detached element" );
1011 assert.equal( detached[ 1 ].style.display, "none", "element in detached tree" );
1013 hiddenDetached.toggle();
1014 hiddenDetached.appendTo( "#qunit-fixture" );
1015 assert.equal( hiddenDetached[ 0 ].style.display, "", "detached, hidden element" );
1016 assert.equal( hiddenDetached[ 1 ].style.display, "", "hidden element in detached tree" );
1018 cascadeHiddenDetached.toggle();
1019 cascadeHiddenDetached.appendTo( "#qunit-fixture" );
1020 assert.equal( cascadeHiddenDetached[ 0 ].style.display, "none",
1021 "detached, cascade-hidden element" );
1022 assert.equal( cascadeHiddenDetached[ 1 ].style.display, "none",
1023 "cascade-hidden element in detached tree" );
1026 QUnit[ jQuery.find.compile && jQuery.fn.toggle && document.body.attachShadow ? "test" : "skip" ]( "shadow toggle()", function( assert ) {
1028 jQuery( "<div id='shadowHost'></div>" ).appendTo( "#qunit-fixture" );
1029 var shadowHost = document.querySelector( "#shadowHost" );
1030 var shadowRoot = shadowHost.attachShadow( { mode: "open" } );
1031 shadowRoot.innerHTML = "" +
1032 "<style>.hidden{display: none;}</style>" +
1033 "<div id='shadowHiddenChild' class='hidden'></div>" +
1034 "<div id='shadowChild'></div>";
1035 var shadowChild = shadowRoot.querySelector( "#shadowChild" );
1036 var shadowHiddenChild = shadowRoot.querySelector( "#shadowHiddenChild" );
1038 var $shadowChild = jQuery( shadowChild );
1039 assert.strictEqual( $shadowChild.css( "display" ), "block", "is visible" );
1040 $shadowChild.toggle();
1041 assert.strictEqual( $shadowChild.css( "display" ), "none", "is hidden" );
1043 $shadowChild = jQuery( shadowHiddenChild );
1044 assert.strictEqual( $shadowChild.css( "display" ), "none", "is hidden" );
1045 $shadowChild.toggle();
1046 assert.strictEqual( $shadowChild.css( "display" ), "block", "is visible" );
1049 QUnit.test( "jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function( assert ) {
1052 var $checkedtest = jQuery( "#checkedtest" );
1053 jQuery.css( $checkedtest[ 0 ], "height" );
1055 assert.ok( jQuery( "input[type='radio']", $checkedtest ).first().attr( "checked" ), "Check first radio still checked." );
1056 assert.ok( !jQuery( "input[type='radio']", $checkedtest ).last().attr( "checked" ), "Check last radio still NOT checked." );
1057 assert.ok( jQuery( "input[type='checkbox']", $checkedtest ).first().attr( "checked" ), "Check first checkbox still checked." );
1058 assert.ok( !jQuery( "input[type='checkbox']", $checkedtest ).last().attr( "checked" ), "Check last checkbox still NOT checked." );
1061 QUnit.test( "internal ref to elem.runtimeStyle (bug #7608)", function( assert ) {
1066 jQuery( "#foo" ).css( { "width": "0%" } ).css( "width" );
1071 assert.ok( result, "elem.runtimeStyle does not throw exception" );
1074 QUnit.test( "computed margins (trac-3333; gh-2237)", function( assert ) {
1077 var $div = jQuery( "#foo" ),
1078 $child = jQuery( "#en" );
1084 assert.equal( $div.css( "marginRight" ), "0px",
1085 "marginRight correctly calculated with a width and display block" );
1088 position: "absolute",
1097 assert.equal( $child.css( "marginLeft" ), "25px", "auto margins are computed to pixels" );
1100 QUnit.test( "box model properties incorrectly returning % instead of px, see #10639 and #12088", function( assert ) {
1103 var container = jQuery( "<div/>" ).width( 400 ).appendTo( "#qunit-fixture" ),
1104 el = jQuery( "<div/>" ).css( { "width": "50%", "marginRight": "50%" } ).appendTo( container ),
1105 el2 = jQuery( "<div/>" ).css( { "width": "50%", "minWidth": "300px", "marginLeft": "25%" } ).appendTo( container );
1107 assert.equal( el.css( "marginRight" ), "200px", "css('marginRight') returning % instead of px, see #10639" );
1108 assert.equal( el2.css( "marginLeft" ), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" );
1111 QUnit.test( "jQuery.cssProps behavior, (bug #8402)", function( assert ) {
1114 var div = jQuery( "<div>" ).appendTo( document.body ).css( {
1115 "position": "absolute",
1119 jQuery.cssProps.top = "left";
1120 assert.equal( div.css( "top" ), "10px", "the fixed property is used when accessing the computed style" );
1121 div.css( "top", "100px" );
1122 assert.equal( div[ 0 ].style.left, "100px", "the fixed property is used when setting the style" );
1124 // cleanup jQuery.cssProps
1125 jQuery.cssProps.top = undefined;
1128 QUnit.test( "widows & orphans #8936", function( assert ) {
1130 var $p = jQuery( "<p>" ).appendTo( "#qunit-fixture" );
1139 assert.equal( $p.css( "widows" ) || jQuery.style( $p[ 0 ], "widows" ), 3, "widows correctly set to 3" );
1140 assert.equal( $p.css( "orphans" ) || jQuery.style( $p[ 0 ], "orphans" ), 3, "orphans correctly set to 3" );
1145 QUnit.test( "can't get css for disconnected in IE<9, see #10254 and #8388", function( assert ) {
1149 span = jQuery( "<span/>" ).css( "background-image", "url(" + baseURL + "1x1.jpg)" );
1150 assert.notEqual( span.css( "background-image" ), null, "can't get background-image in IE<9, see #10254" );
1152 div = jQuery( "<div/>" ).css( "top", 10 );
1153 assert.equal( div.css( "top" ), "10px", "can't get top in IE<9, see #8388" );
1156 QUnit.test( "Ensure styles are retrieving from parsed html on document fragments", function( assert ) {
1160 jQuery.parseHTML( "<span style=\"font-family: Cuprum,sans-serif; font-size: 14px; color: #999999;\">some text</span>" )
1163 assert.equal( $span.css( "font-size" ), "14px", "Font-size retrievable on parsed HTML node" );
1166 QUnit.test( "can't get background-position in IE<9, see #10796", function( assert ) {
1167 var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ),
1183 for ( ; i < l; i++ ) {
1184 div.css( "background-position", units [ i ] );
1185 assert.ok( div.css( "background-position" ), "can't get background-position in IE<9, see #10796" );
1189 if ( jQuery.fn.offset ) {
1190 QUnit.test( "percentage properties for left and top should be transformed to pixels, see #9505", function( assert ) {
1192 var parent = jQuery( "<div style='position:relative;width:200px;height:200px;margin:0;padding:0;border-width:0'></div>" ).appendTo( "#qunit-fixture" ),
1193 div = jQuery( "<div style='position: absolute; width: 20px; height: 20px; top:50%; left:50%'></div>" ).appendTo( parent );
1195 assert.equal( div.css( "top" ), "100px", "position properties not transformed to pixels, see #9505" );
1196 assert.equal( div.css( "left" ), "100px", "position properties not transformed to pixels, see #9505" );
1200 QUnit.test( "Do not append px (#9548, #12990, #2792)", function( assert ) {
1203 var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
1205 $div.css( "fill-opacity", 1 );
1206 assert.equal( $div.css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
1208 $div.css( "font-size", "27px" );
1209 $div.css( "line-height", 2 );
1210 assert.equal( $div.css( "line-height" ), "54px", "Do not append px to 'line-height'" );
1212 $div.css( "column-count", 1 );
1213 if ( $div.css( "column-count" ) !== undefined ) {
1214 assert.equal( $div.css( "column-count" ), 1, "Do not append px to 'column-count'" );
1216 assert.ok( true, "No support for column-count CSS property" );
1219 $div.css( "animation-iteration-count", 2 );
1220 if ( $div.css( "animation-iteration-count" ) !== undefined ) {
1221 // if $div.css( "animation-iteration-count" ) return "1",
1222 // it actually return the default value of animation-iteration-count
1223 assert.equal( $div.css( "animation-iteration-count" ), 2, "Do not append px to 'animation-iteration-count'" );
1225 assert.ok( true, "No support for animation-iteration-count CSS property" );
1231 jQuery( "<div/>" )[ 0 ].style.gridArea === "" ?
1234 ]( "Do not append px to CSS Grid-related properties (gh-4007)", function( assert ) {
1235 assert.expect( 12 );
1237 var prop, value, subProp, subValue, $div,
1240 "grid-row-start": "2",
1241 "grid-row-end": "auto",
1242 "grid-column-start": "auto",
1243 "grid-column-end": "auto"
1246 "grid-column-start": "2",
1247 "grid-column-end": "auto"
1249 "grid-column-end": true,
1250 "grid-column-start": true,
1252 "grid-row-start": "2",
1253 "grid-row-end": "auto"
1255 "grid-row-end": true,
1256 "grid-row-start": true
1259 for ( prop in gridProps ) {
1260 $div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" );
1261 $div.css( prop, 2 );
1263 value = gridProps[ prop ];
1265 if ( typeof value === "object" ) {
1266 for ( subProp in value ) {
1267 subValue = value[ subProp ];
1268 assert.equal( $div.css( subProp ), subValue,
1269 "Do not append px to '" + prop + "' (retrieved " + subProp + ")" );
1272 assert.equal( $div.css( prop ), "2", "Do not append px to '" + prop + "'" );
1279 QUnit.test( "Do not append px to most properties not accepting integer values", function( assert ) {
1282 var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
1284 $div.css( "font-size", "27px" );
1286 $div.css( "font-size", 2 );
1287 assert.equal( $div.css( "font-size" ), "27px", "Do not append px to 'font-size'" );
1289 $div.css( "fontSize", 2 );
1290 assert.equal( $div.css( "fontSize" ), "27px", "Do not append px to 'fontSize'" );
1292 $div.css( "letter-spacing", "2px" );
1293 $div.css( "letter-spacing", 3 );
1294 assert.equal( $div.css( "letter-spacing" ), "2px", "Do not append px to 'letter-spacing'" );
1297 QUnit.test( "Append px to whitelisted properties", function( assert ) {
1299 $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
1301 margin: "marginTop",
1302 marginTop: undefined,
1303 marginRight: undefined,
1304 marginBottom: undefined,
1305 marginLeft: undefined,
1306 padding: "paddingTop",
1307 paddingTop: undefined,
1308 paddingRight: undefined,
1309 paddingBottom: undefined,
1310 paddingLeft: undefined,
1317 minWidth: undefined,
1318 minHeight: undefined,
1319 maxWidth: undefined,
1320 maxHeight: undefined,
1321 border: "borderTopWidth",
1322 borderWidth: "borderTopWidth",
1323 borderTop: "borderTopWidth",
1324 borderTopWidth: undefined,
1325 borderRight: "borderRightWidth",
1326 borderRightWidth: undefined,
1327 borderBottom: "borderBottomWidth",
1328 borderBottomWidth: undefined,
1329 borderLeft: "borderLeftWidth",
1330 borderLeftWidth: undefined
1333 assert.expect( ( Object.keys( whitelist ).length ) * 2 );
1335 for ( prop in whitelist ) {
1336 var propToCheck = whitelist[ prop ] || prop,
1337 kebabProp = prop.replace( /[A-Z]/g, function( match ) {
1338 return "-" + match.toLowerCase();
1340 kebabPropToCheck = propToCheck.replace( /[A-Z]/g, function( match ) {
1341 return "-" + match.toLowerCase();
1344 .css( "position", "absolute" )
1345 .css( "border-style", "solid" );
1346 assert.equal( $div.css( propToCheck ), "3px", "Append px to '" + prop + "'" );
1347 $div.css( kebabProp, 3 )
1348 .css( "position", "absolute" )
1349 .css( "border-style", "solid" );
1350 assert.equal( $div.css( kebabPropToCheck ), "3px", "Append px to '" + kebabProp + "'" );
1354 QUnit.test( "css('width') and css('height') should respect box-sizing, see #11004", function( assert ) {
1357 var el_dis = jQuery( "<div style='width:300px;height:300px;margin:2px;padding:2px;box-sizing:border-box;'>test</div>" ),
1358 el = el_dis.clone().appendTo( "#qunit-fixture" );
1360 assert.equal( el.css( "width" ), el.css( "width", el.css( "width" ) ).css( "width" ), "css('width') is not respecting box-sizing, see #11004" );
1361 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" );
1362 assert.equal( el.css( "height" ), el.css( "height", el.css( "height" ) ).css( "height" ), "css('height') is not respecting box-sizing, see #11004" );
1363 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" );
1367 "css('width') should work correctly before document ready (#14084)",
1368 "css/cssWidthBeforeDocReady.html",
1369 function( assert, jQuery, window, document, cssWidthBeforeDocReady ) {
1371 assert.strictEqual( cssWidthBeforeDocReady, "100px", "elem.css('width') works correctly before document ready" );
1376 "css('width') should work correctly with browser zooming",
1377 "css/cssWidthBrowserZoom.html",
1378 function( assert, jQuery, window, document, widthBeforeSet, widthAfterSet ) {
1380 assert.strictEqual( widthBeforeSet, "100px", "elem.css('width') works correctly with browser zoom" );
1381 assert.strictEqual( widthAfterSet, "100px", "elem.css('width', val) works correctly with browser zoom" );
1386 var supportsFractionalGBCR,
1387 qunitFixture = document.getElementById( "qunit-fixture" ),
1388 div = document.createElement( "div" );
1389 div.style.width = "3.3px";
1390 qunitFixture.appendChild( div );
1391 supportsFractionalGBCR = div.getBoundingClientRect().width.toFixed( 1 ) === "3.3";
1392 qunitFixture.removeChild( div );
1394 QUnit.test( "css('width') and css('height') should return fractional values for nodes in the document", function( assert ) {
1395 if ( !supportsFractionalGBCR ) {
1397 assert.ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
1403 var el = jQuery( "<div class='test-div'></div>" ).appendTo( "#qunit-fixture" );
1404 jQuery( "<style>.test-div { width: 33.3px; height: 88.8px; }</style>" ).appendTo( "#qunit-fixture" );
1406 assert.equal( Number( el.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
1407 "css('width') should return fractional values" );
1408 assert.equal( Number( el.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
1409 "css('height') should return fractional values" );
1412 QUnit.test( "css('width') and css('height') should return fractional values for disconnected nodes", function( assert ) {
1413 if ( !supportsFractionalGBCR ) {
1415 assert.ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
1421 var el = jQuery( "<div style='width: 33.3px; height: 88.8px;'></div>" );
1423 assert.equal( Number( el.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
1424 "css('width') should return fractional values" );
1425 assert.equal( Number( el.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
1426 "css('height') should return fractional values" );
1430 QUnit.test( "certain css values of 'normal' should be convertable to a number, see #8627", function( assert ) {
1433 var el = jQuery( "<div style='letter-spacing:normal;font-weight:normal;'>test</div>" ).appendTo( "#qunit-fixture" );
1435 assert.ok( !isNaN( parseFloat( el.css( "letterSpacing" ) ) ), "css('letterSpacing') not convertable to number, see #8627" );
1436 assert.ok( !isNaN( parseFloat( el.css( "fontWeight" ) ) ), "css('fontWeight') not convertable to number, see #8627" );
1437 assert.equal( typeof el.css( "fontWeight" ), "string", ".css() returns a string" );
1440 // Support: IE 9 only
1441 // Only run this test in IE9
1442 if ( document.documentMode === 9 ) {
1443 QUnit.test( ".css('filter') returns a string in IE9, see #12537", function( assert ) {
1446 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')." );
1450 QUnit.test( "cssHooks - expand", function( assert ) {
1451 assert.expect( 15 );
1454 margin: [ "marginTop", "marginRight", "marginBottom", "marginLeft" ],
1455 borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth" ],
1456 padding: [ "paddingTop", "paddingRight", "paddingBottom", "paddingLeft" ]
1459 jQuery.each( properties, function( property, keys ) {
1460 var hook = jQuery.cssHooks[ property ],
1462 jQuery.each( keys, function( _, key ) {
1463 expected[ key ] = 10;
1465 result = hook.expand( 10 );
1466 assert.deepEqual( result, expected, property + " expands properly with a number" );
1468 jQuery.each( keys, function( _, key ) {
1469 expected[ key ] = "10px";
1471 result = hook.expand( "10px" );
1472 assert.deepEqual( result, expected, property + " expands properly with '10px'" );
1474 expected[ keys[ 1 ] ] = expected[ keys[ 3 ] ] = "20px";
1475 result = hook.expand( "10px 20px" );
1476 assert.deepEqual( result, expected, property + " expands properly with '10px 20px'" );
1478 expected[ keys[ 2 ] ] = "30px";
1479 result = hook.expand( "10px 20px 30px" );
1480 assert.deepEqual( result, expected, property + " expands properly with '10px 20px 30px'" );
1482 expected[ keys[ 3 ] ] = "40px";
1483 result = hook.expand( "10px 20px 30px 40px" );
1484 assert.deepEqual( result, expected, property + " expands properly with '10px 20px 30px 40px'" );
1490 QUnit.test( "css opacity consistency across browsers (#12685)", function( assert ) {
1494 fixture = jQuery( "#qunit-fixture" );
1496 // Append style element
1497 jQuery( "<style>.opacity_t12685 { opacity: 0.1; }</style>" ).appendTo( fixture );
1499 el = jQuery( "<div class='opacity_t12685'></div>" ).appendTo( fixture );
1501 assert.equal( Math.round( el.css( "opacity" ) * 100 ), 10, "opacity from style sheet" );
1502 el.css( "opacity", 0.3 );
1503 assert.equal( Math.round( el.css( "opacity" ) * 100 ), 30, "override opacity" );
1504 el.css( "opacity", "" );
1505 assert.equal( Math.round( el.css( "opacity" ) * 100 ), 10, "remove opacity override" );
1508 QUnit[ jQuery.find.compile ? "test" : "skip" ]( ":visible/:hidden selectors", function( assert ) {
1509 assert.expect( 17 );
1511 var $div, $table, $a;
1513 assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
1514 jQuery( "#nothiddendiv" ).css( { display: "none" } );
1515 assert.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
1516 jQuery( "#nothiddendiv" ).css( { "display": "block" } );
1517 assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
1518 assert.ok( !jQuery( window ).is( ":visible" ), "Calling is(':visible') on window does not throw an exception (#10267)." );
1519 assert.ok( !jQuery( document ).is( ":visible" ), "Calling is(':visible') on document does not throw an exception (#10267)." );
1521 assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
1522 jQuery( "#nothiddendiv" ).css( "display", "none" );
1523 assert.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
1524 jQuery( "#nothiddendiv" ).css( "display", "block" );
1525 assert.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
1527 assert.ok( jQuery( "#siblingspan" ).is( ":visible" ), "Span with no content is visible" );
1528 $div = jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" );
1529 assert.equal( $div.find( ":visible" ).length, 1, "Span with no content is visible" );
1530 $div.css( { width: 0, height: 0, overflow: "hidden" } );
1531 assert.ok( $div.is( ":visible" ), "Div with width and height of 0 is still visible (gh-2227)" );
1533 // Safari 6-7 and iOS 6-7 report 0 width for br elements
1534 // When newer browsers propagate, re-enable this test
1535 // $br = jQuery( "<br/>" ).appendTo( "#qunit-fixture" );
1536 // assert.ok( $br.is( ":visible" ), "br element is visible" );
1538 $table = jQuery( "#table" );
1539 $table.html( "<tr><td style='display:none'>cell</td><td>cell</td></tr>" );
1540 assert.equal( jQuery( "#table td:visible" ).length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements" );
1541 $table.css( "display", "none" ).html( "<tr><td>cell</td><td>cell</td></tr>" );
1542 assert.equal( jQuery( "#table td:visible" ).length, 0, "hidden cell children not perceived as visible (#4512)" );
1544 assert.t( "Is Visible", "#qunit-fixture div:visible:lt(2)", [ "foo", "nothiddendiv" ] );
1545 assert.t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
1546 assert.t( "Is Hidden", "#form input:hidden", [ "hidden1", "hidden2" ] );
1548 $a = jQuery( "<a href='#'><h1>Header</h1></a>" ).appendTo( "#qunit-fixture" );
1549 assert.ok( $a.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" );
1552 QUnit.test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function( assert ) {
1555 var el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", "fake value" );
1556 assert.equal( el.css( "position" ), "absolute", "The old style is kept when setting an unrecognized value" );
1559 // Support: Edge 14 - 16 only
1560 // Edge collapses whitespace-only values when setting a style property and
1561 // there is no easy way for us to work around it. Just skip the test there
1562 // and hope for the better future.
1563 QUnit[ /\bedge\/16\./i.test( navigator.userAgent ) ? "skip" : "test" ](
1564 "Keep the last style if the new one is a non-empty whitespace (gh-3204)",
1565 function( assert ) {
1568 var el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", " " );
1569 assert.equal( el.css( "position" ), "absolute", "The old style is kept when setting to a space" );
1572 QUnit.test( "Reset the style if set to an empty string", function( assert ) {
1574 var el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", "" );
1576 // Some browsers return an empty string; others "static". Both those cases mean the style
1577 // was reset successfully so accept them both.
1578 assert.equal( el.css( "position" ) || "static", "static",
1579 "The style can be reset by setting to an empty string" );
1583 "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)",
1584 function( assert ) {
1585 assert.expect( 24 );
1586 var done = assert.async();
1588 name: "backgroundAttachment",
1590 expected: [ "scroll" ]
1592 name: "backgroundColor",
1593 value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
1594 expected: [ "transparent" ]
1597 // Firefox returns auto's value
1598 name: "backgroundImage",
1599 value: [ "url('test.png')", "url(" + baseURL + "test.png)", "url(\"" + baseURL + "test.png\")" ],
1600 expected: [ "none", "url(\"http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif\")" ]
1602 name: "backgroundPosition",
1604 expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ]
1607 // Firefox returns no-repeat
1608 name: "backgroundRepeat",
1609 value: [ "repeat-y" ],
1610 expected: [ "repeat", "no-repeat" ]
1612 name: "backgroundClip",
1613 value: [ "padding-box" ],
1614 expected: [ "border-box" ]
1616 name: "backgroundOrigin",
1617 value: [ "content-box" ],
1618 expected: [ "padding-box" ]
1620 name: "backgroundSize",
1621 value: [ "80px 60px" ],
1622 expected: [ "auto auto" ]
1625 jQuery.each( styles, function( index, style ) {
1626 var $clone, $clonedChildren,
1627 $source = jQuery( "#firstp" ),
1628 source = $source[ 0 ],
1629 $children = $source.children();
1631 style.expected = style.expected.concat( [ "", "auto" ] );
1633 if ( source.style[ style.name ] === undefined ) {
1634 assert.ok( true, style.name + ": style isn't supported and therefore not an issue" );
1640 $source.css( style.name, style.value[ 0 ] );
1641 $children.css( style.name, style.value[ 0 ] );
1643 $clone = $source.clone();
1644 $clonedChildren = $clone.children();
1646 $clone.css( style.name, "" );
1647 $clonedChildren.css( style.name, "" );
1649 window.setTimeout( function() {
1650 assert.notEqual( $clone.css( style.name ), style.value[ 0 ], "Cloned css was changed" );
1652 assert.ok( jQuery.inArray( $source.css( style.name ) !== -1, style.value ),
1653 "Clearing clone.css() doesn't affect source.css(): " + style.name +
1654 "; result: " + $source.css( style.name ) +
1655 "; expected: " + style.value.join( "," ) );
1657 assert.ok( jQuery.inArray( $children.css( style.name ) !== -1, style.value ),
1658 "Clearing clonedChildren.css() doesn't affect children.css(): " + style.name +
1659 "; result: " + $children.css( style.name ) +
1660 "; expected: " + style.value.join( "," ) );
1664 window.setTimeout( done, 1000 );
1668 // Support: IE <=10 only
1669 // We have to jump through the hoops here in order to test work with "order" CSS property,
1670 // that some browsers do not support. This test is not, strictly speaking, correct,
1671 // but it's the best that we can do.
1673 var style = document.createElement( "div" ).style,
1674 exist = "order" in style || "WebkitOrder" in style;
1677 QUnit.test( "Don't append px to CSS \"order\" value (#14049)", function( assert ) {
1680 var $elem = jQuery( "<div/>" );
1682 $elem.css( "order", 2 );
1683 assert.equal( $elem.css( "order" ), "2", "2 on order" );
1688 QUnit.test( "Do not throw on frame elements from css method (#15098)", function( assert ) {
1691 var frameWin, frameDoc,
1692 frameElement = document.createElement( "iframe" ),
1693 frameWrapDiv = document.createElement( "div" );
1695 frameWrapDiv.appendChild( frameElement );
1696 document.body.appendChild( frameWrapDiv );
1697 frameWin = frameElement.contentWindow;
1698 frameDoc = frameWin.document;
1700 frameDoc.write( "<!doctype html><html><body><div>Hi</div></body></html>" );
1703 frameWrapDiv.style.display = "none";
1706 jQuery( frameDoc.body ).css( "direction" );
1707 assert.ok( true, "It didn't throw" );
1709 assert.ok( false, "It did throw" );
1714 var vendorPrefixes = [ "Webkit", "Moz", "ms" ];
1716 function resetCssPropsFor( name ) {
1717 delete jQuery.cssProps[ name ];
1718 jQuery.each( vendorPrefixes, function( index, prefix ) {
1719 delete jQuery.cssProps[ prefix + name[ 0 ].toUpperCase() + name.slice( 1 ) ];
1723 QUnit.test( "Don't default to a cached previously used wrong prefixed name (gh-2015)", function( assert ) {
1725 // Note: this test needs a property we know is only supported in a prefixed version
1726 // by at least one of our main supported browsers. This may get out of date so let's
1727 // use -(webkit|moz)-appearance as well as those two are not on a standards track.
1728 var appearanceName, transformName, elem, elemStyle,
1729 transformVal = "translate(5px, 2px)",
1730 emptyStyle = document.createElement( "div" ).style;
1732 if ( "appearance" in emptyStyle ) {
1733 appearanceName = "appearance";
1735 jQuery.each( vendorPrefixes, function( index, prefix ) {
1736 var prefixedProp = prefix + "Appearance";
1737 if ( prefixedProp in emptyStyle ) {
1738 appearanceName = prefixedProp;
1743 if ( "transform" in emptyStyle ) {
1744 transformName = "transform";
1746 jQuery.each( vendorPrefixes, function( index, prefix ) {
1747 var prefixedProp = prefix + "Transform";
1748 if ( prefixedProp in emptyStyle ) {
1749 transformName = prefixedProp;
1754 assert.expect( !!appearanceName + !!transformName + 1 );
1756 resetCssPropsFor( "appearance" );
1757 resetCssPropsFor( "transform" );
1759 elem = jQuery( "<div/>" )
1761 msAppearance: "none",
1764 // Only the ms prefix is used to make sure we haven't e.g. set
1765 // webkitTransform ourselves in the test.
1766 msTransform: transformVal,
1767 transform: transformVal
1769 elemStyle = elem[ 0 ].style;
1771 if ( appearanceName ) {
1772 assert.equal( elemStyle[ appearanceName ], "none", "setting properly-prefixed appearance" );
1774 if ( transformName ) {
1775 assert.equal( elemStyle[ transformName ], transformVal, "setting properly-prefixed transform" );
1777 assert.equal( elemStyle[ "undefined" ], undefined, "Nothing writes to node.style.undefined" );
1780 QUnit.test( "Don't detect fake set properties on a node when caching the prefixed version", function( assert ) {
1783 var elem = jQuery( "<div/>" ),
1784 style = elem[ 0 ].style;
1785 style.MozFakeProperty = "old value";
1786 elem.css( "fakeProperty", "new value" );
1788 assert.equal( style.MozFakeProperty, "old value", "Fake prefixed property is not cached" );
1794 var supportsCssVars,
1795 elem = jQuery( "<div>" ).appendTo( document.body ),
1798 div.style.setProperty( "--prop", "value" );
1799 supportsCssVars = !!getComputedStyle( div ).getPropertyValue( "--prop" );
1802 QUnit[ supportsCssVars ? "test" : "skip" ]( "css(--customProperty)", function( assert ) {
1803 jQuery( "#qunit-fixture" ).append(
1805 " .test__customProperties {\n" +
1806 " --prop1:val1;\n" +
1807 " --prop2: val2;\n" +
1808 " --prop3:val3 ;\n" +
1809 " --prop4:\"val4\";\n" +
1810 " --prop5:'val5';\n" +
1815 var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
1816 $elem = jQuery( "<div>" ).addClass( "test__customProperties" )
1817 .appendTo( "#qunit-fixture" ),
1818 webkit = /\bsafari\b/i.test( navigator.userAgent ) &&
1819 !/\firefox\b/i.test( navigator.userAgent ) &&
1820 !/\edge\b/i.test( navigator.userAgent ),
1821 oldSafari = webkit && ( /\b9\.\d(\.\d+)* safari/i.test( navigator.userAgent ) ||
1822 /\b10\.0(\.\d+)* safari/i.test( navigator.userAgent ) ||
1823 /iphone os (?:9|10)_/i.test( navigator.userAgent ) ),
1832 assert.expect( expected );
1834 div.css( "--color", "blue" );
1835 assert.equal( div.css( "--color" ), "blue", "Modified CSS custom property using string" );
1837 div.css( "--color", "yellow" );
1838 assert.equal( div.css( "--color" ), "yellow", "Overwrite CSS custom property" );
1840 div.css( { "--color": "red" } );
1841 assert.equal( div.css( "--color" ), "red", "Modified CSS custom property using object" );
1843 div.css( { "--mixedCase": "green" } );
1844 div.css( { "--mixed-case": "red" } );
1845 assert.equal( div.css( "--mixedCase" ), "green",
1846 "Modified CSS custom property with mixed case" );
1848 div.css( { "--theme-dark": "purple" } );
1849 div.css( { "--themeDark": "red" } );
1850 assert.equal( div.css( "--theme-dark" ), "purple",
1851 "Modified CSS custom property with dashed name" );
1853 assert.equal( $elem.css( "--prop1" ), "val1", "Basic CSS custom property" );
1855 // Support: Safari 9.1-10.0 only
1856 // Safari collapses whitespaces & quotes. Ignore it.
1858 assert.equal( $elem.css( "--prop2" ), " val2", "Preceding whitespace maintained" );
1859 assert.equal( $elem.css( "--prop3" ), "val3 ", "Following whitespace maintained" );
1862 // Support: Chrome 49-55, Safari 9.1-10.0
1863 // Chrome treats single quotes as double ones.
1864 // Safari treats double quotes as single ones.
1866 assert.equal( $elem.css( "--prop4" ), "\"val4\"", "Works with double quotes" );
1867 assert.equal( $elem.css( "--prop5" ), "'val5'", "Works with single quotes" );
1871 QUnit[ supportsCssVars ? "test" : "skip" ]( "Don't append px to CSS vars", function( assert ) {
1874 var $div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
1878 .css( "--line-height", 4 )
1879 .css( "--lineHeight", 5 );
1881 assert.equal( $div.css( "--a" ), "3", "--a: 3" );
1882 assert.equal( $div.css( "--line-height" ), "4", "--line-height: 4" );
1883 assert.equal( $div.css( "--lineHeight" ), "5", "--lineHeight: 5" );
1890 if ( document.documentMode ) {
1891 // Make sure explicitly provided IE vendor prefix (`-ms-`) is not converted
1892 // to a non-working `Ms` prefix in JavaScript.
1893 QUnit.test( "IE vendor prefixes are not mangled", function( assert ) {
1896 var div = jQuery( "<div>" ).appendTo( "#qunit-fixture" );
1898 div.css( "-ms-grid-row", "1" );
1900 assert.strictEqual( div.css( "-ms-grid-row" ), "1", "IE vendor prefixing" );