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
, widthBeforeSet
, widthAfterSet
) {
1172 assert
.strictEqual( widthBeforeSet
, "100px", "elem.css('width') works correctly with browser zoom" );
1173 assert
.strictEqual( widthAfterSet
, "100px", "elem.css('width', val) works correctly with browser zoom" );
1178 var supportsFractionalGBCR
,
1179 qunitFixture
= document
.getElementById( "qunit-fixture" ),
1180 div
= document
.createElement( "div" );
1181 div
.style
.width
= "3.3px";
1182 qunitFixture
.appendChild( div
);
1183 supportsFractionalGBCR
= div
.getBoundingClientRect().width
.toFixed( 1 ) === "3.3";
1184 qunitFixture
.removeChild( div
);
1186 QUnit
.test( "css('width') and css('height') should return fractional values for nodes in the document", function( assert
) {
1187 if ( !supportsFractionalGBCR
) {
1189 assert
.ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
1195 var el
= jQuery( "<div class='test-div'></div>" ).appendTo( "#qunit-fixture" );
1196 jQuery( "<style>.test-div { width: 33.3px; height: 88.8px; }</style>" ).appendTo( "#qunit-fixture" );
1198 assert
.equal( Number( el
.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
1199 "css('width') should return fractional values" );
1200 assert
.equal( Number( el
.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
1201 "css('height') should return fractional values" );
1204 QUnit
.test( "css('width') and css('height') should return fractional values for disconnected nodes", function( assert
) {
1205 if ( !supportsFractionalGBCR
) {
1207 assert
.ok( true, "This browser doesn't support fractional values in getBoundingClientRect()" );
1213 var el
= jQuery( "<div style='width: 33.3px; height: 88.8px;'></div>" );
1215 assert
.equal( Number( el
.css( "width" ).replace( /px$/, "" ) ).toFixed( 1 ), "33.3",
1216 "css('width') should return fractional values" );
1217 assert
.equal( Number( el
.css( "height" ).replace( /px$/, "" ) ).toFixed( 1 ), "88.8",
1218 "css('height') should return fractional values" );
1222 QUnit
.test( "certain css values of 'normal' should be convertable to a number, see #8627", function( assert
) {
1225 var el
= jQuery( "<div style='letter-spacing:normal;font-weight:normal;'>test</div>" ).appendTo( "#qunit-fixture" );
1227 assert
.ok( !isNaN( parseFloat( el
.css( "letterSpacing" ) ) ), "css('letterSpacing') not convertable to number, see #8627" );
1228 assert
.ok( !isNaN( parseFloat( el
.css( "fontWeight" ) ) ), "css('fontWeight') not convertable to number, see #8627" );
1229 assert
.equal( typeof el
.css( "fontWeight" ), "string", ".css() returns a string" );
1232 // Support: IE 9 only
1233 // Only run this test in IE9
1234 if ( document
.documentMode
=== 9 ) {
1235 QUnit
.test( ".css('filter') returns a string in IE9, see #12537", function( assert
) {
1238 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')." );
1242 QUnit
.test( "cssHooks - expand", function( assert
) {
1243 assert
.expect( 15 );
1246 margin
: [ "marginTop", "marginRight", "marginBottom", "marginLeft" ],
1247 borderWidth
: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth" ],
1248 padding
: [ "paddingTop", "paddingRight", "paddingBottom", "paddingLeft" ]
1251 jQuery
.each( properties
, function( property
, keys
) {
1252 var hook
= jQuery
.cssHooks
[ property
],
1254 jQuery
.each( keys
, function( _
, key
) {
1255 expected
[ key
] = 10;
1257 result
= hook
.expand( 10 );
1258 assert
.deepEqual( result
, expected
, property
+ " expands properly with a number" );
1260 jQuery
.each( keys
, function( _
, key
) {
1261 expected
[ key
] = "10px";
1263 result
= hook
.expand( "10px" );
1264 assert
.deepEqual( result
, expected
, property
+ " expands properly with '10px'" );
1266 expected
[ keys
[ 1 ] ] = expected
[ keys
[ 3 ] ] = "20px";
1267 result
= hook
.expand( "10px 20px" );
1268 assert
.deepEqual( result
, expected
, property
+ " expands properly with '10px 20px'" );
1270 expected
[ keys
[ 2 ] ] = "30px";
1271 result
= hook
.expand( "10px 20px 30px" );
1272 assert
.deepEqual( result
, expected
, property
+ " expands properly with '10px 20px 30px'" );
1274 expected
[ keys
[ 3 ] ] = "40px";
1275 result
= hook
.expand( "10px 20px 30px 40px" );
1276 assert
.deepEqual( result
, expected
, property
+ " expands properly with '10px 20px 30px 40px'" );
1282 QUnit
.test( "css opacity consistency across browsers (#12685)", function( assert
) {
1286 fixture
= jQuery( "#qunit-fixture" );
1288 // Append style element
1289 jQuery( "<style>.opacity_t12685 { opacity: 0.1; }</style>" ).appendTo( fixture
);
1291 el
= jQuery( "<div class='opacity_t12685'></div>" ).appendTo( fixture
);
1293 assert
.equal( Math
.round( el
.css( "opacity" ) * 100 ), 10, "opacity from style sheet" );
1294 el
.css( "opacity", 0.3 );
1295 assert
.equal( Math
.round( el
.css( "opacity" ) * 100 ), 30, "override opacity" );
1296 el
.css( "opacity", "" );
1297 assert
.equal( Math
.round( el
.css( "opacity" ) * 100 ), 10, "remove opacity override" );
1300 QUnit
[ jQuery
.find
.compile
? "test" : "skip" ]( ":visible/:hidden selectors", function( assert
) {
1301 assert
.expect( 17 );
1303 var $div
, $table
, $a
;
1305 assert
.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
1306 jQuery( "#nothiddendiv" ).css( { display
: "none" } );
1307 assert
.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
1308 jQuery( "#nothiddendiv" ).css( { "display": "block" } );
1309 assert
.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
1310 assert
.ok( !jQuery( window
).is( ":visible" ), "Calling is(':visible') on window does not throw an exception (#10267)." );
1311 assert
.ok( !jQuery( document
).is( ":visible" ), "Calling is(':visible') on document does not throw an exception (#10267)." );
1313 assert
.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modifying CSS display: Assert element is visible" );
1314 jQuery( "#nothiddendiv" ).css( "display", "none" );
1315 assert
.ok( !jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is hidden" );
1316 jQuery( "#nothiddendiv" ).css( "display", "block" );
1317 assert
.ok( jQuery( "#nothiddendiv" ).is( ":visible" ), "Modified CSS display: Assert element is visible" );
1319 assert
.ok( jQuery( "#siblingspan" ).is( ":visible" ), "Span with no content is visible" );
1320 $div
= jQuery( "<div><span></span></div>" ).appendTo( "#qunit-fixture" );
1321 assert
.equal( $div
.find( ":visible" ).length
, 1, "Span with no content is visible" );
1322 $div
.css( { width
: 0, height
: 0, overflow
: "hidden" } );
1323 assert
.ok( $div
.is( ":visible" ), "Div with width and height of 0 is still visible (gh-2227)" );
1325 // Safari 6-7 and iOS 6-7 report 0 width for br elements
1326 // When newer browsers propagate, re-enable this test
1327 // $br = jQuery( "<br/>" ).appendTo( "#qunit-fixture" );
1328 // ok( $br.is( ":visible" ), "br element is visible" );
1330 $table
= jQuery( "#table" );
1331 $table
.html( "<tr><td style='display:none'>cell</td><td>cell</td></tr>" );
1332 assert
.equal( jQuery( "#table td:visible" ).length
, 1, "hidden cell is not perceived as visible (#4512). Works on table elements" );
1333 $table
.css( "display", "none" ).html( "<tr><td>cell</td><td>cell</td></tr>" );
1334 assert
.equal( jQuery( "#table td:visible" ).length
, 0, "hidden cell children not perceived as visible (#4512)" );
1336 assert
.t( "Is Visible", "#qunit-fixture div:visible:lt(2)", [ "foo", "nothiddendiv" ] );
1337 assert
.t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
1338 assert
.t( "Is Hidden", "#form input:hidden", [ "hidden1", "hidden2" ] );
1340 $a
= jQuery( "<a href='#'><h1>Header</h1></a>" ).appendTo( "#qunit-fixture" );
1341 assert
.ok( $a
.is( ":visible" ), "Anchor tag with flow content is visible (gh-2227)" );
1344 QUnit
.test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function( assert
) {
1347 var el
= jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", "fake value" );
1348 assert
.equal( el
.css( "position" ), "absolute", "The old style is kept when setting an unrecognized value" );
1351 // Support: Edge 14 - 16 only
1352 // Edge collapses whitespace-only values when setting a style property and
1353 // there is no easy way for us to work around it. Just skip the test there
1354 // and hope for the better future.
1355 QUnit
[ /\bedge\/16\./i.test( navigator
.userAgent
) ? "skip" : "test" ](
1356 "Keep the last style if the new one is a non-empty whitespace (gh-3204)",
1357 function( assert
) {
1360 var el
= jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", " " );
1361 assert
.equal( el
.css( "position" ), "absolute", "The old style is kept when setting to a space" );
1364 QUnit
.test( "Reset the style if set to an empty string", function( assert
) {
1366 var el
= jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", "" );
1368 // Some browsers return an empty string; others "static". Both those cases mean the style
1369 // was reset successfully so accept them both.
1370 assert
.equal( el
.css( "position" ) || "static", "static",
1371 "The style can be reset by setting to an empty string" );
1375 "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)",
1377 function( assert
) {
1378 var done
= assert
.async();
1380 name
: "backgroundAttachment",
1382 expected
: [ "scroll" ]
1384 name
: "backgroundColor",
1385 value
: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
1386 expected
: [ "transparent" ]
1389 // Firefox returns auto's value
1390 name
: "backgroundImage",
1391 value
: [ "url('test.png')", "url(" + baseURL
+ "test.png)", "url(\"" + baseURL
+ "test.png\")" ],
1392 expected
: [ "none", "url(\"http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif\")" ]
1394 name
: "backgroundPosition",
1396 expected
: [ "0% 0%", "-1000px 0px", "-1000px 0%" ]
1399 // Firefox returns no-repeat
1400 name
: "backgroundRepeat",
1401 value
: [ "repeat-y" ],
1402 expected
: [ "repeat", "no-repeat" ]
1404 name
: "backgroundClip",
1405 value
: [ "padding-box" ],
1406 expected
: [ "border-box" ]
1408 name
: "backgroundOrigin",
1409 value
: [ "content-box" ],
1410 expected
: [ "padding-box" ]
1412 name
: "backgroundSize",
1413 value
: [ "80px 60px" ],
1414 expected
: [ "auto auto" ]
1417 jQuery
.each( styles
, function( index
, style
) {
1418 var $clone
, $clonedChildren
,
1419 $source
= jQuery( "#firstp" ),
1420 source
= $source
[ 0 ],
1421 $children
= $source
.children();
1423 style
.expected
= style
.expected
.concat( [ "", "auto" ] );
1425 if ( source
.style
[ style
.name
] === undefined ) {
1426 assert
.ok( true, style
.name
+ ": style isn't supported and therefore not an issue" );
1432 $source
.css( style
.name
, style
.value
[ 0 ] );
1433 $children
.css( style
.name
, style
.value
[ 0 ] );
1435 $clone
= $source
.clone();
1436 $clonedChildren
= $clone
.children();
1438 $clone
.css( style
.name
, "" );
1439 $clonedChildren
.css( style
.name
, "" );
1441 window
.setTimeout( function() {
1442 assert
.notEqual( $clone
.css( style
.name
), style
.value
[ 0 ], "Cloned css was changed" );
1444 assert
.ok( jQuery
.inArray( $source
.css( style
.name
) !== -1, style
.value
),
1445 "Clearing clone.css() doesn't affect source.css(): " + style
.name
+
1446 "; result: " + $source
.css( style
.name
) +
1447 "; expected: " + style
.value
.join( "," ) );
1449 assert
.ok( jQuery
.inArray( $children
.css( style
.name
) !== -1, style
.value
),
1450 "Clearing clonedChildren.css() doesn't affect children.css(): " + style
.name
+
1451 "; result: " + $children
.css( style
.name
) +
1452 "; expected: " + style
.value
.join( "," ) );
1456 window
.setTimeout( done
, 1000 );
1460 // Support: IE <=10 only
1461 // We have to jump through the hoops here in order to test work with "order" CSS property,
1462 // that some browsers do not support. This test is not, strictly speaking, correct,
1463 // but it's the best that we can do.
1465 var style
= document
.createElement( "div" ).style
,
1466 exist
= "order" in style
|| "WebkitOrder" in style
;
1469 QUnit
.test( "Don't append px to CSS \"order\" value (#14049)", function( assert
) {
1472 var $elem
= jQuery( "<div/>" );
1474 $elem
.css( "order", 2 );
1475 assert
.equal( $elem
.css( "order" ), "2", "2 on order" );
1480 QUnit
.test( "Do not throw on frame elements from css method (#15098)", function( assert
) {
1483 var frameWin
, frameDoc
,
1484 frameElement
= document
.createElement( "iframe" ),
1485 frameWrapDiv
= document
.createElement( "div" );
1487 frameWrapDiv
.appendChild( frameElement
);
1488 document
.body
.appendChild( frameWrapDiv
);
1489 frameWin
= frameElement
.contentWindow
;
1490 frameDoc
= frameWin
.document
;
1492 frameDoc
.write( "<!doctype html><html><body><div>Hi</div></body></html>" );
1495 frameWrapDiv
.style
.display
= "none";
1498 jQuery( frameDoc
.body
).css( "direction" );
1499 assert
.ok( true, "It didn't throw" );
1501 assert
.ok( false, "It did throw" );
1506 var vendorPrefixes
= [ "Webkit", "Moz", "ms" ];
1508 function resetCssPropsFor( name
) {
1509 delete jQuery
.cssProps
[ name
];
1510 jQuery
.each( vendorPrefixes
, function( index
, prefix
) {
1511 delete jQuery
.cssProps
[ prefix
+ name
[ 0 ].toUpperCase() + name
.slice( 1 ) ];
1515 QUnit
.test( "Don't default to a cached previously used wrong prefixed name (gh-2015)", function( assert
) {
1517 // Note: this test needs a property we know is only supported in a prefixed version
1518 // by at least one of our main supported browsers. This may get out of date so let's
1519 // use -(webkit|moz)-appearance as well as those two are not on a standards track.
1520 var appearanceName
, transformName
, elem
, elemStyle
,
1521 transformVal
= "translate(5px, 2px)",
1522 emptyStyle
= document
.createElement( "div" ).style
;
1524 if ( "appearance" in emptyStyle
) {
1525 appearanceName
= "appearance";
1527 jQuery
.each( vendorPrefixes
, function( index
, prefix
) {
1528 var prefixedProp
= prefix
+ "Appearance";
1529 if ( prefixedProp
in emptyStyle
) {
1530 appearanceName
= prefixedProp
;
1535 if ( "transform" in emptyStyle
) {
1536 transformName
= "transform";
1538 jQuery
.each( vendorPrefixes
, function( index
, prefix
) {
1539 var prefixedProp
= prefix
+ "Transform";
1540 if ( prefixedProp
in emptyStyle
) {
1541 transformName
= prefixedProp
;
1546 assert
.expect( !!appearanceName
+ !!transformName
+ 1 );
1548 resetCssPropsFor( "appearance" );
1549 resetCssPropsFor( "transform" );
1551 elem
= jQuery( "<div/>" )
1553 msAppearance
: "none",
1556 // Only the ms prefix is used to make sure we haven't e.g. set
1557 // webkitTransform ourselves in the test.
1558 msTransform
: transformVal
,
1559 transform
: transformVal
1561 elemStyle
= elem
[ 0 ].style
;
1563 if ( appearanceName
) {
1564 assert
.equal( elemStyle
[ appearanceName
], "none", "setting properly-prefixed appearance" );
1566 if ( transformName
) {
1567 assert
.equal( elemStyle
[ transformName
], transformVal
, "setting properly-prefixed transform" );
1569 assert
.equal( elemStyle
[ "undefined" ], undefined, "Nothing writes to node.style.undefined" );
1572 QUnit
.test( "Don't detect fake set properties on a node when caching the prefixed version", function( assert
) {
1575 var elem
= jQuery( "<div/>" ),
1576 style
= elem
[ 0 ].style
;
1577 style
.MozFakeProperty
= "old value";
1578 elem
.css( "fakeProperty", "new value" );
1580 assert
.equal( style
.MozFakeProperty
, "old value", "Fake prefixed property is not cached" );
1586 var supportsCssVars
,
1587 elem
= jQuery( "<div>" ).appendTo( document
.body
),
1590 div
.style
.setProperty( "--prop", "value" );
1591 supportsCssVars
= !!getComputedStyle( div
).getPropertyValue( "--prop" );
1594 QUnit
[ supportsCssVars
? "test" : "skip" ]( "css(--customProperty)", function( assert
) {
1595 jQuery( "#qunit-fixture" ).append(
1597 " .test__customProperties {\n" +
1598 " --prop1:val1;\n" +
1599 " --prop2: val2;\n" +
1600 " --prop3:val3 ;\n" +
1601 " --prop4:\"val4\";\n" +
1602 " --prop5:'val5';\n" +
1607 var div
= jQuery( "<div>" ).appendTo( "#qunit-fixture" ),
1608 $elem
= jQuery( "<div>" ).addClass( "test__customProperties" )
1609 .appendTo( "#qunit-fixture" ),
1610 webkit
= /\bsafari\b/i.test( navigator
.userAgent
) &&
1611 !/\firefox\b/i.test( navigator
.userAgent
) &&
1612 !/\edge\b/i.test( navigator
.userAgent
),
1613 oldSafari
= webkit
&& ( /\b9\.\d(\.\d+)* safari/i.test( navigator
.userAgent
) ||
1614 /\b10\.0(\.\d+)* safari/i.test( navigator
.userAgent
) ||
1615 /iphone os (?:9|10)_/i.test( navigator
.userAgent
) ),
1624 assert
.expect( expected
);
1626 div
.css( "--color", "blue" );
1627 assert
.equal( div
.css( "--color" ), "blue", "Modified CSS custom property using string" );
1629 div
.css( "--color", "yellow" );
1630 assert
.equal( div
.css( "--color" ), "yellow", "Overwrite CSS custom property" );
1632 div
.css( { "--color": "red" } );
1633 assert
.equal( div
.css( "--color" ), "red", "Modified CSS custom property using object" );
1635 div
.css( { "--mixedCase": "green" } );
1636 div
.css( { "--mixed-case": "red" } );
1637 assert
.equal( div
.css( "--mixedCase" ), "green",
1638 "Modified CSS custom property with mixed case" );
1640 div
.css( { "--theme-dark": "purple" } );
1641 div
.css( { "--themeDark": "red" } );
1642 assert
.equal( div
.css( "--theme-dark" ), "purple",
1643 "Modified CSS custom property with dashed name" );
1645 assert
.equal( $elem
.css( "--prop1" ), "val1", "Basic CSS custom property" );
1647 // Support: Safari 9.1-10.0 only
1648 // Safari collapses whitespaces & quotes. Ignore it.
1650 assert
.equal( $elem
.css( "--prop2" ), " val2", "Preceding whitespace maintained" );
1651 assert
.equal( $elem
.css( "--prop3" ), "val3 ", "Following whitespace maintained" );
1654 // Support: Chrome 49-55, Safari 9.1-10.0
1655 // Chrome treats single quotes as double ones.
1656 // Safari treats double quotes as single ones.
1658 assert
.equal( $elem
.css( "--prop4" ), "\"val4\"", "Works with double quotes" );
1659 assert
.equal( $elem
.css( "--prop5" ), "'val5'", "Works with single quotes" );
1663 QUnit
[ supportsCssVars
? "test" : "skip" ]( "Don't append px to CSS vars", function( assert
) {
1666 var $div
= jQuery( "<div>" ).appendTo( "#qunit-fixture" );
1670 .css( "--line-height", 4 )
1671 .css( "--lineHeight", 5 );
1673 assert
.equal( $div
.css( "--a" ), "3", "--a: 3" );
1674 assert
.equal( $div
.css( "--line-height" ), "4", "--line-height: 4" );
1675 assert
.equal( $div
.css( "--lineHeight" ), "5", "--lineHeight: 5" );