3 module("css", { teardown: moduleTeardown });
5 test("css(String|Hash)", function() {
8 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 notEqual( $child.css("width"), "20px", "Retrieving a width percentage on the child of a hidden div returns percentage" );
14 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 equal( div.css("width"), "0px", "Width on disconnected node." );
21 equal( div.css("height"), "0px", "Height on disconnected node." );
23 div.css({ "width": 4, "height": 4 });
25 equal( div.css("width"), "4px", "Width on disconnected node." );
26 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 equal( div2.find("input").css("height"), "20px", "Height on hidden input." );
31 equal( div2.find("textarea").css("height"), "20px", "Height on hidden textarea." );
32 equal( div2.find("div").css("height"), "20px", "Height on hidden textarea." );
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 equal( parseFloat(jQuery("#nothiddendiv").css("width")), 0, "Test negative width set to 0");
43 equal( parseFloat(jQuery("#nothiddendiv").css("height")), 0, "Test negative height set to 0");
45 equal( jQuery("<div style='display: none;'/>").css("display"), "none", "Styles on disconnected nodes");
47 jQuery("#floatTest").css({"float": "right"});
48 equal( jQuery("#floatTest").css("float"), "right", "Modified CSS float using \"float\": Assert float is right");
49 jQuery("#floatTest").css({"font-size": "30px"});
50 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 equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
55 jQuery("#foo").css({"opacity": parseFloat(n)});
56 equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
58 jQuery("#foo").css({"opacity": ""});
59 equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
61 equal( jQuery("#empty").css("opacity"), "0", "Assert opacity is accessible via filter property set in stylesheet in IE" );
62 jQuery("#empty").css({ "opacity": "1" });
63 equal( jQuery("#empty").css("opacity"), "1", "Assert opacity is taken from style attribute when set vs stylesheet in IE with filters" );
65 div = jQuery("#nothiddendiv");
66 child = jQuery("#nothiddendivchild");
68 equal( parseInt(div.css("fontSize"), 10), 16, "Verify fontSize px set." );
69 equal( parseInt(div.css("font-size"), 10), 16, "Verify fontSize px set." );
70 equal( parseInt(child.css("fontSize"), 10), 16, "Verify fontSize px set." );
71 equal( parseInt(child.css("font-size"), 10), 16, "Verify fontSize px set." );
73 child.css("height", "100%");
74 equal( child[0].style.height, "100%", "Make sure the height is being set correctly." );
76 child.attr("class", "em");
77 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 equal( prctval, checkval, "Verify fontSize % set." );
90 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 equal( child[0].style.height, old, "Make sure height isn't changed on NaN." );
99 child.css("height", null);
100 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 equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on NaN." );
109 child.css("font-size", null);
110 equal( child[0].style.fontSize, old, "Make sure font-size isn't changed on null." );
112 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 strictEqual( div.css( "z-index" ), "1000",
116 "Make sure that a string z-index is returned from css('z-index') (#14432)." );
119 test( "css() explicit and relative values", 29, function() {
120 var $elem = jQuery("#nothiddendiv");
122 $elem.css({ "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 });
123 equal( $elem.css("width"), "1px", "Initial css set or width/height works (hash)" );
124 equal( $elem.css("paddingLeft"), "1px", "Initial css set of paddingLeft works (hash)" );
125 equal( $elem.css("opacity"), "1", "Initial css set of opacity works (hash)" );
127 $elem.css({ width: "+=9" });
128 equal( $elem.css("width"), "10px", "'+=9' on width (hash)" );
130 $elem.css({ "width": "-=9" });
131 equal( $elem.css("width"), "1px", "'-=9' on width (hash)" );
133 $elem.css({ "width": "+=9px" });
134 equal( $elem.css("width"), "10px", "'+=9px' on width (hash)" );
136 $elem.css({ "width": "-=9px" });
137 equal( $elem.css("width"), "1px", "'-=9px' on width (hash)" );
139 $elem.css( "width", "+=9" );
140 equal( $elem.css("width"), "10px", "'+=9' on width (params)" );
142 $elem.css( "width", "-=9" ) ;
143 equal( $elem.css("width"), "1px", "'-=9' on width (params)" );
145 $elem.css( "width", "+=9px" );
146 equal( $elem.css("width"), "10px", "'+=9px' on width (params)" );
148 $elem.css( "width", "-=9px" );
149 equal( $elem.css("width"), "1px", "'-=9px' on width (params)" );
151 $elem.css( "width", "-=-9px" );
152 equal( $elem.css("width"), "10px", "'-=-9px' on width (params)" );
154 $elem.css( "width", "+=-9px" );
155 equal( $elem.css("width"), "1px", "'+=-9px' on width (params)" );
157 $elem.css({ "paddingLeft": "+=4" });
158 equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (hash)" );
160 $elem.css({ "paddingLeft": "-=4" });
161 equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (hash)" );
163 $elem.css({ "paddingLeft": "+=4px" });
164 equal( $elem.css("paddingLeft"), "5px", "'+=4px' on paddingLeft (hash)" );
166 $elem.css({ "paddingLeft": "-=4px" });
167 equal( $elem.css("paddingLeft"), "1px", "'-=4px' on paddingLeft (hash)" );
169 $elem.css({ "padding-left": "+=4" });
170 equal( $elem.css("paddingLeft"), "5px", "'+=4' on padding-left (hash)" );
172 $elem.css({ "padding-left": "-=4" });
173 equal( $elem.css("paddingLeft"), "1px", "'-=4' on padding-left (hash)" );
175 $elem.css({ "padding-left": "+=4px" });
176 equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (hash)" );
178 $elem.css({ "padding-left": "-=4px" });
179 equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (hash)" );
181 $elem.css( "paddingLeft", "+=4" );
182 equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (params)" );
184 $elem.css( "paddingLeft", "-=4" );
185 equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (params)" );
187 $elem.css( "padding-left", "+=4px" );
188 equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (params)" );
190 $elem.css( "padding-left", "-=4px" );
191 equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (params)" );
193 $elem.css({ "opacity": "-=0.5" });
194 equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (hash)" );
196 $elem.css({ "opacity": "+=0.5" });
197 equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (hash)" );
199 $elem.css( "opacity", "-=0.5" );
200 equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (params)" );
202 $elem.css( "opacity", "+=0.5" );
203 equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (params)" );
206 test( "css() non-px relative values (gh-1711)", 17, function() {
209 $child = jQuery( "#nothiddendivchild" ),
210 add = function( prop, val, unit ) {
212 adjustment = ( val < 0 ? "-=" : "+=" ) + Math.abs( val ) + unit,
213 message = prop + ": " + adjustment,
215 expected = cssOld + val * units[ prop ][ unit ];
218 $child.css( prop, adjustment );
219 cssCurrent = parseFloat( $child.css( prop ) );
221 // Require a difference of no more than one pixel
222 difference = Math.abs( cssCurrent - expected );
223 if ( difference <= 1 ) {
226 // ...or fail with actual and expected values
228 ok( false, message + " (actual " + cssCurrent + ", expected " + expected + ")" );
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, "100%" ).css( prop ) ) / 100
243 jQuery( "#nothiddendiv" ).css({ height: 1, padding: 0, width: 400 });
244 $child.css({ height: 1, padding: 0 });
247 cssCurrent = parseFloat( $child.css( "width", "50%" ).css( "width" ) );
248 add( "width", 25, "%" );
249 add( "width", -50, "%" );
250 add( "width", 10, "em" );
251 add( "width", 10, "pt" );
252 add( "width", -2.3, "pt" );
253 add( "width", 5, "pc" );
254 add( "width", -5, "em" );
255 add( "width", +2, "cm" );
256 add( "width", -15, "mm" );
257 add( "width", 21, "px" );
259 getUnits( "lineHeight" );
260 cssCurrent = parseFloat( $child.css( "lineHeight", "1em" ).css( "lineHeight" ) );
261 add( "lineHeight", 2, "em" );
262 add( "lineHeight", -10, "px" );
263 add( "lineHeight", 20, "pt" );
264 add( "lineHeight", 30, "pc" );
265 add( "lineHeight", 1, "cm" );
266 add( "lineHeight", -20, "mm" );
267 add( "lineHeight", 50, "%" );
270 test("css(String, Object)", function() {
272 var j, div, display, ret, success;
274 jQuery("#floatTest").css("float", "left");
275 equal( jQuery("#floatTest").css("float"), "left", "Modified CSS float using \"float\": Assert float is left");
276 jQuery("#floatTest").css("font-size", "20px");
277 equal( jQuery("#floatTest").css("font-size"), "20px", "Modified CSS font-size: Assert font-size is 20px");
279 jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
280 jQuery("#foo").css("opacity", n);
281 equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
282 jQuery("#foo").css("opacity", parseFloat(n));
283 equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
285 jQuery("#foo").css("opacity", "");
286 equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
288 // using contents will get comments regular, text, and comment nodes
289 j = jQuery("#nonnodes").contents();
290 j.css("overflow", "visible");
291 equal( j.css("overflow"), "visible", "Check node,textnode,comment css works" );
292 equal( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
294 div = jQuery("#nothiddendiv");
295 display = div.css("display");
296 ret = div.css("display", undefined);
298 equal( ret, div, "Make sure setting undefined returns the original set." );
299 equal( div.css("display"), display, "Make sure that the display wasn't changed." );
303 jQuery( "#foo" ).css( "backgroundColor", "rgba(0, 0, 0, 0.1)" );
308 ok( success, "Setting RGBA values does not throw Error (#5509)" );
310 jQuery( "#foo" ).css( "font", "7px/21px sans-serif" );
311 strictEqual( jQuery( "#foo" ).css( "line-height" ), "21px",
312 "Set font shorthand property (#14759)" );
315 test( "css(String, Object) with negative values", function() {
318 jQuery( "#nothiddendiv" ).css( "margin-top", "-10px" );
319 jQuery( "#nothiddendiv" ).css( "margin-left", "-10px" );
320 equal( jQuery( "#nothiddendiv" ).css( "margin-top" ), "-10px", "Ensure negative top margins work." );
321 equal( jQuery( "#nothiddendiv" ).css( "margin-left" ), "-10px", "Ensure negative left margins work." );
323 jQuery( "#nothiddendiv" ).css( "position", "absolute" );
324 jQuery( "#nothiddendiv" ).css( "top", "-20px" );
325 jQuery( "#nothiddendiv" ).css( "left", "-20px" );
326 equal( jQuery( "#nothiddendiv" ).css( "top" ), "-20px", "Ensure negative top values work." );
327 equal( jQuery( "#nothiddendiv" ).css( "left" ), "-20px", "Ensure negative left values work." );
330 test( "css(Array)", function() {
334 "overflow": "visible",
340 elem = jQuery("<div></div>").appendTo("#qunit-fixture");
342 deepEqual( elem.css( expectedMany ).css([ "overflow", "width" ]), expectedMany, "Getting multiple element array" );
343 deepEqual( elem.css( expectedSingle ).css([ "width" ]), expectedSingle, "Getting single element array" );
346 test("css(String, Function)", function() {
350 sizes = ["10px", "20px", "30px"];
352 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
353 "<div class='cssFunction'></div>" +
354 "<div class='cssFunction'></div></div>")
359 jQuery("#cssFunctionTest div").css("font-size", function() {
360 var size = sizes[index];
367 jQuery("#cssFunctionTest div").each(function() {
368 var computedSize = jQuery(this).css("font-size"),
369 expectedSize = sizes[index];
370 equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
374 jQuery("#cssFunctionTest").remove();
377 test("css(String, Function) with incoming value", function() {
381 sizes = ["10px", "20px", "30px"];
383 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
384 "<div class='cssFunction'></div>" +
385 "<div class='cssFunction'></div></div>")
390 jQuery("#cssFunctionTest div").css("font-size", function() {
391 var size = sizes[index];
398 jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
399 var expectedSize = sizes[index];
400 equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
405 jQuery("#cssFunctionTest").remove();
408 test("css(Object) where values are Functions", function() {
412 sizes = ["10px", "20px", "30px"];
414 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
415 "<div class='cssFunction'></div>" +
416 "<div class='cssFunction'></div></div>")
421 jQuery("#cssFunctionTest div").css({"fontSize": function() {
422 var size = sizes[index];
429 jQuery("#cssFunctionTest div").each(function() {
430 var computedSize = jQuery(this).css("font-size"),
431 expectedSize = sizes[index];
432 equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
436 jQuery("#cssFunctionTest").remove();
439 test("css(Object) where values are Functions with incoming values", function() {
443 sizes = ["10px", "20px", "30px"];
445 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
446 "<div class='cssFunction'></div>" +
447 "<div class='cssFunction'></div></div>")
452 jQuery("#cssFunctionTest div").css({"fontSize": function() {
453 var size = sizes[index];
460 jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
461 var expectedSize = sizes[index];
462 equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
467 jQuery("#cssFunctionTest").remove();
470 test("show(); hide()", function() {
476 hiddendiv = jQuery("div.hidden");
478 equal( hiddendiv.css("display"), "none", "Non-detached div hidden" );
480 equal( hiddendiv.css("display"), "block", "Pre-hidden div shown" );
482 div = jQuery("<div>").hide();
483 equal( div.css("display"), "none", "Detached div hidden" );
484 div.appendTo("#qunit-fixture").show();
485 equal( div.css("display"), "block", "Pre-hidden div shown" );
489 test("show();", function() {
493 var hiddendiv, div, pass, old, test;
494 hiddendiv = jQuery("div.hidden");
496 equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
498 hiddendiv.css("display", "block");
499 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
502 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
504 hiddendiv.css("display","");
507 div = jQuery("#qunit-fixture div");
508 div.show().each(function(){
509 if ( this.style.display === "none" ) {
515 // #show-tests * is set display: none in CSS
516 jQuery("#qunit-fixture").append("<div id='show-tests'><div><p><a href='#'></a></p><code></code><pre></pre><span></span></div><table><thead><tr><th></th></tr></thead><tbody><tr><td></td></tr></tbody></table><ul><li></li></ul></div><table id='test-table'></table>");
518 old = jQuery("#test-table").show().css("display") !== "table";
519 jQuery("#test-table").remove();
528 "table" : old ? "block" : "table",
529 "thead" : old ? "block" : "table-header-group",
530 "tbody" : old ? "block" : "table-row-group",
531 "tr" : old ? "block" : "table-row",
532 "th" : old ? "block" : "table-cell",
533 "td" : old ? "block" : "table-cell",
535 "li" : old ? "block" : "list-item"
538 jQuery.each(test, function(selector, expected) {
539 var elem = jQuery(selector, "#show-tests").show();
540 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
543 // Make sure that showing or hiding a text node doesn't cause an error
544 jQuery("<div>test</div> text <span>test</span>").show().remove();
545 jQuery("<div>test</div> text <span>test</span>").hide().remove();
548 test("show() resolves correct default display #8099", function() {
550 var tt8099 = jQuery("<tt/>").appendTo("body"),
551 dfn8099 = jQuery("<dfn/>", { "html": "foo"}).appendTo("body");
553 equal( tt8099.css("display"), "none", "default display override for all tt" );
554 equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
556 equal( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
558 equal( tt8099.hide().css("display"), "none", "default display override for all tt" );
559 equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
561 equal( dfn8099.css("display"), "none", "default display override for all dfn" );
562 equal( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" );
568 test( "show() resolves correct default display for detached nodes", function(){
571 var div, span, tr, trDisplay;
573 div = jQuery("<div class='hidden'>");
574 div.show().appendTo("#qunit-fixture");
575 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." );
577 div = jQuery("<div style='display: none'>");
578 div.show().appendTo("#qunit-fixture");
579 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." );
581 span = jQuery("<span class='hidden'/>");
582 span.show().appendTo("#qunit-fixture");
583 equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." );
585 span = jQuery("<span style='display: inline'/>");
586 span.show().appendTo("#qunit-fixture");
587 equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." );
589 div = jQuery("<div><div class='hidden'></div></div>").children("div");
590 div.show().appendTo("#qunit-fixture");
591 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." );
593 div = jQuery("<div><div style='display: none'></div></div>").children("div");
594 div.show().appendTo("#qunit-fixture");
595 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." );
597 div = jQuery("div.hidden");
599 equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." );
602 span = jQuery("<span>");
603 span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" );
604 equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." );
607 div = jQuery("<div>");
608 div.show().appendTo("#qunit-fixture");
609 ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." );
612 div = jQuery( document.createElement("div") );
613 div.show().appendTo("#qunit-fixture");
614 equal( div.css("display"), "block", "Make sure a pre-created element has default display." );
617 div = jQuery("<div style='display: inline'/>");
618 div.show().appendTo("#qunit-fixture");
619 equal( div.css("display"), "inline", "Make sure that element has same display when it was created." );
622 tr = jQuery("<tr/>");
623 jQuery("#table").append( tr );
624 trDisplay = tr.css( "display" );
625 tr.detach().hide().show();
627 equal( tr[ 0 ].style.display, trDisplay, "For detached tr elements, display should always be like for attached trs" );
630 span = jQuery("<span/>").hide().show();
631 equal( span[ 0 ].style.display, "inline", "For detached span elements, display should always be inline" );
635 test("show() resolves correct default display #10227", 4, function() {
636 var html = jQuery( document.documentElement ),
637 body = jQuery( "body" );
639 body.append( "<p class='ddisplay'>a<style>body{display:none}</style></p>" );
641 equal( body.css("display"), "none", "Initial display for body element: none" );
644 equal( body.css("display"), "block", "Correct display for body element: block" );
646 body.append( "<p class='ddisplay'>a<style>html{display:none}</style></p>" );
648 equal( html.css("display"), "none", "Initial display for html element: none" );
651 equal( html.css( "display" ), "block", "Correct display for html element: block" );
653 jQuery( ".ddisplay" ).remove();
656 test("show() resolves correct default display when iframe display:none #12904", function() {
659 var ddisplay = jQuery(
660 "<p id='ddisplay'>a<style>p{display:none}iframe{display:none !important}</style></p>"
663 equal( ddisplay.css("display"), "none", "Initial display: none" );
666 equal( ddisplay.css("display"), "block", "Correct display: block" );
671 test("toggle()", function() {
676 ok( x.is(":visible"), "is visible" );
678 ok( x.is(":hidden"), "is hidden" );
680 ok( x.is(":visible"), "is visible again" );
683 ok( x.is(":visible"), "is visible" );
685 ok( x.is(":hidden"), "is hidden" );
687 ok( x.is(":visible"), "is visible again" );
689 div = jQuery("<div style='display:none'><div></div></div>").appendTo("#qunit-fixture");
691 strictEqual( x.toggle().css( "display" ), "none", "is hidden" );
692 strictEqual( x.toggle().css( "display" ), "block", "is visible" );
694 // Ensure hide() is called when toggled (#12148)
695 oldHide = jQuery.fn.hide;
696 jQuery.fn.hide = function() {
697 ok( true, name + " method called on toggle" );
698 return oldHide.apply( this, arguments );
700 x.toggle( name === "show" );
701 jQuery.fn.hide = oldHide;
704 test("hide hidden elements (bug #7141)", function() {
707 var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
708 equal( div.css("display"), "none", "Element is hidden by default" );
710 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
712 equal( div.css("display"), "block", "Show a double-hidden element" );
717 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
720 var $checkedtest = jQuery("#checkedtest");
721 jQuery.css($checkedtest[0], "height");
723 ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
724 ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
725 ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
726 ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
729 test("internal ref to elem.runtimeStyle (bug #7608)", function () {
734 jQuery("#foo").css( { "width": "0%" } ).css("width");
739 ok( result, "elem.runtimeStyle does not throw exception" );
742 test("marginRight computed style (bug #3333)", function() {
745 var $div = jQuery("#foo");
751 equal($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block");
754 test("box model properties incorrectly returning % instead of px, see #10639 and #12088", function() {
757 var container = jQuery("<div/>").width( 400 ).appendTo("#qunit-fixture"),
758 el = jQuery("<div/>").css({ "width": "50%", "marginRight": "50%" }).appendTo( container ),
759 el2 = jQuery("<div/>").css({ "width": "50%", "minWidth": "300px", "marginLeft": "25%" }).appendTo( container );
761 equal( el.css("marginRight"), "200px", "css('marginRight') returning % instead of px, see #10639" );
762 equal( el2.css("marginLeft"), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" );
765 test("jQuery.cssProps behavior, (bug #8402)", function() {
768 var div = jQuery( "<div>" ).appendTo(document.body).css({
769 "position": "absolute",
773 jQuery.cssProps.top = "left";
774 equal( div.css("top"), "10px", "the fixed property is used when accessing the computed style");
775 div.css("top", "100px");
776 equal( div[0].style.left, "100px", "the fixed property is used when setting the style");
777 // cleanup jQuery.cssProps
778 jQuery.cssProps.top = undefined;
781 test("widows & orphans #8936", function () {
783 var $p = jQuery("<p>").appendTo("#qunit-fixture");
792 equal( $p.css( "widows" ) || jQuery.style( $p[0], "widows" ), 3, "widows correctly set to 3" );
793 equal( $p.css( "orphans" ) || jQuery.style( $p[0], "orphans" ), 3, "orphans correctly set to 3" );
798 test("can't get css for disconnected in IE<9, see #10254 and #8388", function() {
802 span = jQuery( "<span/>" ).css( "background-image", "url(data/1x1.jpg)" );
803 notEqual( span.css( "background-image" ), null, "can't get background-image in IE<9, see #10254" );
805 div = jQuery( "<div/>" ).css( "top", 10 );
806 equal( div.css( "top" ), "10px", "can't get top in IE<9, see #8388" );
809 test("can't get background-position in IE<9, see #10796", function() {
810 var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ),
826 for( ; i < l; i++ ) {
827 div.css( "background-position", units [ i ] );
828 ok( div.css( "background-position" ), "can't get background-position in IE<9, see #10796" );
832 if ( jQuery.fn.offset ) {
833 test("percentage properties for left and top should be transformed to pixels, see #9505", function() {
835 var parent = jQuery("<div style='position:relative;width:200px;height:200px;margin:0;padding:0;border-width:0'></div>").appendTo( "#qunit-fixture" ),
836 div = jQuery("<div style='position: absolute; width: 20px; height: 20px; top:50%; left:50%'></div>").appendTo( parent );
838 equal( div.css("top"), "100px", "position properties not transformed to pixels, see #9505" );
839 equal( div.css("left"), "100px", "position properties not transformed to pixels, see #9505" );
843 test("Do not append px (#9548, #12990)", function() {
846 var $div = jQuery("<div>").appendTo("#qunit-fixture");
848 $div.css( "fill-opacity", 1 );
849 // Support: Android 2.3 (no support for fill-opacity)
850 if ( $div.css( "fill-opacity" ) ) {
851 equal( $div.css( "fill-opacity" ), 1, "Do not append px to 'fill-opacity'" );
853 ok( true, "No support for fill-opacity CSS property" );
856 $div.css( "column-count", 1 );
857 if ( $div.css("column-count") ) {
858 equal( $div.css("column-count"), 1, "Do not append px to 'column-count'" );
860 ok( true, "No support for column-count CSS property" );
864 test("css('width') and css('height') should respect box-sizing, see #11004", function() {
867 // Support: Android 2.3 (-webkit-box-sizing).
868 var el_dis = jQuery("<div style='width:300px;height:300px;margin:2px;padding:2px;-webkit-box-sizing:border-box;box-sizing:border-box;'>test</div>"),
869 el = el_dis.clone().appendTo("#qunit-fixture");
871 equal( el.css("width"), el.css("width", el.css("width")).css("width"), "css('width') is not respecting box-sizing, see #11004");
872 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");
873 equal( el.css("height"), el.css("height", el.css("height")).css("height"), "css('height') is not respecting box-sizing, see #11004");
874 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");
877 testIframeWithCallback( "css('width') should work correctly before document ready (#14084)",
878 "css/cssWidthBeforeDocReady.html",
879 function( cssWidthBeforeDocReady ) {
881 strictEqual( cssWidthBeforeDocReady, "100px", "elem.css('width') works correctly before document ready" );
885 test("certain css values of 'normal' should be convertable to a number, see #8627", function() {
888 var el = jQuery("<div style='letter-spacing:normal;font-weight:normal;'>test</div>").appendTo("#qunit-fixture");
890 ok( jQuery.isNumeric( parseFloat( el.css("letterSpacing") ) ), "css('letterSpacing') not convertable to number, see #8627" );
891 ok( jQuery.isNumeric( parseFloat( el.css("fontWeight") ) ), "css('fontWeight') not convertable to number, see #8627" );
892 equal( typeof el.css( "fontWeight" ), "string", ".css() returns a string" );
895 // only run this test in IE9
896 if ( document.documentMode === 9 ) {
897 test( ".css('filter') returns a string in IE9, see #12537", 1, function() {
898 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')." );
902 test( "cssHooks - expand", function() {
906 margin: [ "marginTop", "marginRight", "marginBottom", "marginLeft" ],
907 borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"],
908 padding: [ "paddingTop", "paddingRight", "paddingBottom", "paddingLeft" ]
911 jQuery.each( properties, function( property, keys ) {
912 var hook = jQuery.cssHooks[ property ],
914 jQuery.each( keys, function( _, key ) {
915 expected[ key ] = 10;
917 result = hook.expand( 10 );
918 deepEqual( result, expected, property + " expands properly with a number" );
920 jQuery.each( keys, function( _, key ) {
921 expected[ key ] = "10px";
923 result = hook.expand( "10px" );
924 deepEqual( result, expected, property + " expands properly with '10px'" );
926 expected[ keys[1] ] = expected[ keys[3] ] = "20px";
927 result = hook.expand( "10px 20px" );
928 deepEqual( result, expected, property + " expands properly with '10px 20px'" );
930 expected[ keys[2] ] = "30px";
931 result = hook.expand( "10px 20px 30px" );
932 deepEqual( result, expected, property + " expands properly with '10px 20px 30px'" );
934 expected[ keys[3] ] = "40px";
935 result = hook.expand( "10px 20px 30px 40px" );
936 deepEqual( result, expected, property + " expands properly with '10px 20px 30px 40px'" );
942 test( "css opacity consistency across browsers (#12685)", function() {
946 fixture = jQuery("#qunit-fixture");
948 // Append style element
949 jQuery("<style>.opacityWithSpaces_t12685 { opacity: 0.1; filter: alpha(opacity = 10); } .opacityNoSpaces_t12685 { opacity: 0.2; filter: alpha(opacity=20); }</style>").appendTo( fixture );
951 el = jQuery("<div class='opacityWithSpaces_t12685'></div>").appendTo(fixture);
953 equal( Math.round( el.css("opacity") * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" );
954 el.removeClass("opacityWithSpaces_t12685").addClass("opacityNoSpaces_t12685");
955 equal( Math.round( el.css("opacity") * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" );
956 el.css( "opacity", 0.3 );
957 equal( Math.round( el.css("opacity") * 100 ), 30, "override opacity" );
958 el.css( "opacity", "" );
959 equal( Math.round( el.css("opacity") * 100 ), 20, "remove opacity override" );
962 test( ":visible/:hidden selectors", function() {
965 var $newDiv, $br, $table;
967 ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" );
968 jQuery("#nothiddendiv").css({ display: "none" });
969 ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden" );
970 jQuery("#nothiddendiv").css({ "display": "block" });
971 ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
972 ok( !jQuery(window).is(":visible"), "Calling is(':visible') on window does not throw an exception (#10267).");
973 ok( !jQuery(document).is(":visible"), "Calling is(':visible') on document does not throw an exception (#10267).");
975 ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
976 jQuery("#nothiddendiv").css("display", "none");
977 ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden");
978 jQuery("#nothiddendiv").css("display", "block");
979 ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
981 ok( !jQuery("#siblingspan").is(":visible"), "Span with no content not visible (#13132)" );
982 $newDiv = jQuery("<div><span></span></div>").appendTo("#qunit-fixture");
983 equal( $newDiv.find(":visible").length, 0, "Span with no content not visible (#13132)" );
984 $br = jQuery("<br/>").appendTo("#qunit-fixture");
985 ok( !$br.is(":visible"), "br element not visible (#10406)");
987 $table = jQuery("#table");
988 $table.html("<tr><td style='display:none'>cell</td><td>cell</td></tr>");
989 equal(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements");
990 $table.css("display", "none").html("<tr><td>cell</td><td>cell</td></tr>");
991 equal(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible (#4512)");
993 t( "Is Visible", "#qunit-fixture div:visible:lt(2)", ["foo", "nothiddendiv"] );
994 t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
995 t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] );
998 test( "Keep the last style if the new one isn't recognized by the browser (#14836)", function() {
1002 el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", "fake value" );
1003 equal( el.css( "position" ), "absolute", "The old style is kept when setting an unrecognized value" );
1004 el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", " " );
1005 equal( el.css( "position" ), "absolute", "The old style is kept when setting to a space" );
1008 test( "Reset the style if set to an empty string", function() {
1010 var el = jQuery( "<div></div>" ).css( "position", "absolute" ).css( "position", "" );
1011 // Some browsers return an empty string; others "static". Both those cases mean the style
1012 // was reset successfully so accept them both.
1013 equal( el.css( "position" ) || "static", "static",
1014 "The style can be reset by setting to an empty string" );
1017 asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 24, function() {
1018 var baseUrl = document.location.href.replace( /([^\/]*)$/, "" ),
1020 name: "backgroundAttachment",
1022 expected: [ "scroll" ]
1024 name: "backgroundColor",
1025 value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
1026 expected: ["transparent"]
1028 // Firefox returns auto's value
1029 name: "backgroundImage",
1030 value: [ "url('test.png')", "url(" + baseUrl + "test.png)", "url(\"" + baseUrl + "test.png\")" ],
1031 expected: [ "none", "url(\"http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif\")" ]
1033 name: "backgroundPosition",
1035 expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ]
1037 // Firefox returns no-repeat
1038 name: "backgroundRepeat",
1039 value: ["repeat-y"],
1040 expected: [ "repeat", "no-repeat" ]
1042 name: "backgroundClip",
1043 value: ["padding-box"],
1044 expected: ["border-box"]
1046 name: "backgroundOrigin",
1047 value: ["content-box"],
1048 expected: ["padding-box"]
1050 name: "backgroundSize",
1051 value: ["80px 60px"],
1052 expected: [ "auto auto" ]
1055 jQuery.each(styles, function( index, style ) {
1056 var $clone, $clonedChildren,
1057 $source = jQuery( "#firstp" ),
1058 source = $source[ 0 ],
1059 $children = $source.children();
1061 style.expected = style.expected.concat( [ "", "auto" ] );
1063 if ( source.style[ style.name ] === undefined ) {
1064 ok( true, style.name + ": style isn't supported and therefore not an issue" );
1070 $source.css( style.name, style.value[ 0 ] );
1071 $children.css( style.name, style.value[ 0 ] );
1073 $clone = $source.clone();
1074 $clonedChildren = $clone.children();
1076 $clone.css( style.name, "" );
1077 $clonedChildren.css( style.name, "" );
1079 window.setTimeout(function() {
1080 notEqual( $clone.css( style.name ), style.value[ 0 ], "Cloned css was changed" );
1082 ok( jQuery.inArray( $source.css( style.name ) !== -1, style.value ),
1083 "Clearing clone.css() doesn't affect source.css(): " + style.name +
1084 "; result: " + $source.css( style.name ) +
1085 "; expected: " + style.value.join( "," ) );
1087 ok( jQuery.inArray( $children.css( style.name ) !== -1, style.value ),
1088 "Clearing clonedChildren.css() doesn't affect children.css(): " + style.name +
1089 "; result: " + $children.css( style.name ) +
1090 "; expected: " + style.value.join( "," ) );
1094 window.setTimeout( start, 1000 );
1097 asyncTest( "Make sure initialized display value for disconnected nodes is correct (#13310)", 4, function() {
1098 var display = jQuery("#display").css("display"),
1099 div = jQuery("<div/>");
1101 equal( div.css( "display", "inline" ).hide().show().appendTo("body").css( "display" ), "inline", "Initialized display value has returned" );
1104 div.css( "display", "none" ).hide();
1105 equal( jQuery._data( div[ 0 ], "olddisplay" ), undefined, "olddisplay is undefined after hiding a detached and hidden element" );
1108 div.css( "display", "inline-block" ).hide().appendTo("body").fadeIn(function() {
1109 equal( div.css( "display" ), "inline-block", "Initialized display value has returned" );
1115 equal( jQuery._data( jQuery("#display").css( "display", "inline" ).hide()[ 0 ], "olddisplay" ), display,
1116 "display: * !Important value should used as initialized display" );
1117 jQuery._removeData( jQuery("#display")[ 0 ] );
1120 test( "show() after hide() should always set display to initial value (#14750)", 1, function() {
1121 var div = jQuery( "<div />" ),
1122 fixture = jQuery( "#qunit-fixture" );
1124 fixture.append( div );
1126 div.css( "display", "inline" ).hide().show().css( "display", "list-item" ).hide().show();
1127 equal( div.css( "display" ), "list-item", "should get last set display value" );
1130 // Support: IE < 11, Safari < 7
1131 // We have to jump through the hoops here in order to test work with "order" CSS property,
1132 // that some browsers do not support. This test is not, strictly speaking, correct,
1133 // but it's the best that we can do.
1135 var style = document.createElement( "div" ).style,
1136 exist = "order" in style || "WebkitOrder" in style;
1139 test( "Don't append px to CSS \"order\" value (#14049)", 1, function() {
1140 var $elem = jQuery( "<div/>" );
1142 $elem.css( "order", 2 );
1143 equal( $elem.css( "order" ), "2", "2 on order" );
1148 test( "Do not throw on frame elements from css method (#15098)", 1, function() {
1149 var frameWin, frameDoc,
1150 frameElement = document.createElement( "iframe" ),
1151 frameWrapDiv = document.createElement( "div" );
1153 frameWrapDiv.appendChild( frameElement );
1154 document.body.appendChild( frameWrapDiv );
1155 frameWin = frameElement.contentWindow;
1156 frameDoc = frameWin.document;
1158 frameDoc.write( "<!doctype html><html><body><div>Hi</div></body></html>" );
1161 frameWrapDiv.style.display = "none";
1164 jQuery( frameDoc.body ).css( "direction" );
1165 ok( true, "It didn't throw" );
1167 ok( false, "It did throw" );