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." );
113 test( "css() explicit and relative values", 29, function() {
114 var $elem = jQuery("#nothiddendiv");
116 $elem.css({ "width": 1, "height": 1, "paddingLeft": "1px", "opacity": 1 });
117 equal( $elem.css("width"), "1px", "Initial css set or width/height works (hash)" );
118 equal( $elem.css("paddingLeft"), "1px", "Initial css set of paddingLeft works (hash)" );
119 equal( $elem.css("opacity"), "1", "Initial css set of opacity works (hash)" );
121 $elem.css({ width: "+=9" });
122 equal( $elem.css("width"), "10px", "'+=9' on width (hash)" );
124 $elem.css({ "width": "-=9" });
125 equal( $elem.css("width"), "1px", "'-=9' on width (hash)" );
127 $elem.css({ "width": "+=9px" });
128 equal( $elem.css("width"), "10px", "'+=9px' on width (hash)" );
130 $elem.css({ "width": "-=9px" });
131 equal( $elem.css("width"), "1px", "'-=9px' on width (hash)" );
133 $elem.css( "width", "+=9" );
134 equal( $elem.css("width"), "10px", "'+=9' on width (params)" );
136 $elem.css( "width", "-=9" ) ;
137 equal( $elem.css("width"), "1px", "'-=9' on width (params)" );
139 $elem.css( "width", "+=9px" );
140 equal( $elem.css("width"), "10px", "'+=9px' on width (params)" );
142 $elem.css( "width", "-=9px" );
143 equal( $elem.css("width"), "1px", "'-=9px' 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({ "paddingLeft": "+=4" });
152 equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (hash)" );
154 $elem.css({ "paddingLeft": "-=4" });
155 equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (hash)" );
157 $elem.css({ "paddingLeft": "+=4px" });
158 equal( $elem.css("paddingLeft"), "5px", "'+=4px' on paddingLeft (hash)" );
160 $elem.css({ "paddingLeft": "-=4px" });
161 equal( $elem.css("paddingLeft"), "1px", "'-=4px' on paddingLeft (hash)" );
163 $elem.css({ "padding-left": "+=4" });
164 equal( $elem.css("paddingLeft"), "5px", "'+=4' on padding-left (hash)" );
166 $elem.css({ "padding-left": "-=4" });
167 equal( $elem.css("paddingLeft"), "1px", "'-=4' on padding-left (hash)" );
169 $elem.css({ "padding-left": "+=4px" });
170 equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (hash)" );
172 $elem.css({ "padding-left": "-=4px" });
173 equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (hash)" );
175 $elem.css( "paddingLeft", "+=4" );
176 equal( $elem.css("paddingLeft"), "5px", "'+=4' on paddingLeft (params)" );
178 $elem.css( "paddingLeft", "-=4" );
179 equal( $elem.css("paddingLeft"), "1px", "'-=4' on paddingLeft (params)" );
181 $elem.css( "padding-left", "+=4px" );
182 equal( $elem.css("paddingLeft"), "5px", "'+=4px' on padding-left (params)" );
184 $elem.css( "padding-left", "-=4px" );
185 equal( $elem.css("paddingLeft"), "1px", "'-=4px' on padding-left (params)" );
187 $elem.css({ "opacity": "-=0.5" });
188 equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (hash)" );
190 $elem.css({ "opacity": "+=0.5" });
191 equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (hash)" );
193 $elem.css( "opacity", "-=0.5" );
194 equal( $elem.css("opacity"), "0.5", "'-=0.5' on opacity (params)" );
196 $elem.css( "opacity", "+=0.5" );
197 equal( $elem.css("opacity"), "1", "'+=0.5' on opacity (params)" );
200 test("css(String, Object)", function() {
202 var j, div, display, ret, success;
204 jQuery("#nothiddendiv").css("top", "-1em");
205 ok( jQuery("#nothiddendiv").css("top"), -16, "Check negative number in EMs." );
207 jQuery("#floatTest").css("float", "left");
208 equal( jQuery("#floatTest").css("float"), "left", "Modified CSS float using \"float\": Assert float is left");
209 jQuery("#floatTest").css("font-size", "20px");
210 equal( jQuery("#floatTest").css("font-size"), "20px", "Modified CSS font-size: Assert font-size is 20px");
212 jQuery.each("0,0.25,0.5,0.75,1".split(","), function(i, n) {
213 jQuery("#foo").css("opacity", n);
214 equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a String" );
215 jQuery("#foo").css("opacity", parseFloat(n));
216 equal( jQuery("#foo").css("opacity"), parseFloat(n), "Assert opacity is " + parseFloat(n) + " as a Number" );
218 jQuery("#foo").css("opacity", "");
219 equal( jQuery("#foo").css("opacity"), "1", "Assert opacity is 1 when set to an empty String" );
221 // using contents will get comments regular, text, and comment nodes
222 j = jQuery("#nonnodes").contents();
223 j.css("overflow", "visible");
224 equal( j.css("overflow"), "visible", "Check node,textnode,comment css works" );
225 // opera sometimes doesn't update 'display' correctly, see #2037
226 jQuery("#t2037")[0].innerHTML = jQuery("#t2037")[0].innerHTML;
227 equal( jQuery("#t2037 .hidden").css("display"), "none", "Make sure browser thinks it is hidden" );
229 div = jQuery("#nothiddendiv");
230 display = div.css("display");
231 ret = div.css("display", undefined);
233 equal( ret, div, "Make sure setting undefined returns the original set." );
234 equal( div.css("display"), display, "Make sure that the display wasn't changed." );
236 // Test for Bug #5509
239 jQuery("#foo").css("backgroundColor", "rgba(0, 0, 0, 0.1)");
244 ok( success, "Setting RGBA values does not throw Error" );
247 test( "css(Array)", function() {
251 "overflow": "visible",
257 elem = jQuery("<div></div>").appendTo("#qunit-fixture");
259 deepEqual( elem.css( expectedMany ).css([ "overflow", "width" ]), expectedMany, "Getting multiple element array" );
260 deepEqual( elem.css( expectedSingle ).css([ "width" ]), expectedSingle, "Getting single element array" );
263 test("css(String, Function)", function() {
267 sizes = ["10px", "20px", "30px"];
269 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
270 "<div class='cssFunction'></div>" +
271 "<div class='cssFunction'></div></div>")
276 jQuery("#cssFunctionTest div").css("font-size", function() {
277 var size = sizes[index];
284 jQuery("#cssFunctionTest div").each(function() {
285 var computedSize = jQuery(this).css("font-size"),
286 expectedSize = sizes[index];
287 equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
291 jQuery("#cssFunctionTest").remove();
294 test("css(String, Function) with incoming value", function() {
298 sizes = ["10px", "20px", "30px"];
300 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
301 "<div class='cssFunction'></div>" +
302 "<div class='cssFunction'></div></div>")
307 jQuery("#cssFunctionTest div").css("font-size", function() {
308 var size = sizes[index];
315 jQuery("#cssFunctionTest div").css("font-size", function(i, computedSize) {
316 var expectedSize = sizes[index];
317 equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
322 jQuery("#cssFunctionTest").remove();
325 test("css(Object) where values are Functions", function() {
329 sizes = ["10px", "20px", "30px"];
331 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
332 "<div class='cssFunction'></div>" +
333 "<div class='cssFunction'></div></div>")
338 jQuery("#cssFunctionTest div").css({"fontSize": function() {
339 var size = sizes[index];
346 jQuery("#cssFunctionTest div").each(function() {
347 var computedSize = jQuery(this).css("font-size"),
348 expectedSize = sizes[index];
349 equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
353 jQuery("#cssFunctionTest").remove();
356 test("css(Object) where values are Functions with incoming values", function() {
360 sizes = ["10px", "20px", "30px"];
362 jQuery("<div id='cssFunctionTest'><div class='cssFunction'></div>" +
363 "<div class='cssFunction'></div>" +
364 "<div class='cssFunction'></div></div>")
369 jQuery("#cssFunctionTest div").css({"fontSize": function() {
370 var size = sizes[index];
377 jQuery("#cssFunctionTest div").css({"font-size": function(i, computedSize) {
378 var expectedSize = sizes[index];
379 equal( computedSize, expectedSize, "Div #" + index + " should be " + expectedSize );
384 jQuery("#cssFunctionTest").remove();
387 test("show(); hide()", function() {
390 var hiddendiv, div, pass, old, test;
392 hiddendiv = jQuery("div.hidden");
394 equal( hiddendiv.css("display"), "none", "Non-detached div hidden" );
396 equal( hiddendiv.css("display"), "block", "Pre-hidden div shown" );
398 div = jQuery("<div>").hide();
399 equal( div.css("display"), "none", "Detached div hidden" );
400 div.appendTo("#qunit-fixture").show();
401 equal( div.css("display"), "block", "Pre-hidden div shown" );
405 hiddendiv = jQuery("div.hidden");
407 equal(jQuery.css( hiddendiv[0], "display"), "none", "hiddendiv is display: none");
409 hiddendiv.css("display", "block");
410 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
413 equal(jQuery.css( hiddendiv[0], "display"), "block", "hiddendiv is display: block");
415 hiddendiv.css("display","");
418 div = jQuery("#qunit-fixture div");
419 div.show().each(function(){
420 if ( this.style.display === "none" ) {
426 // #show-tests * is set display: none in CSS
427 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>");
429 old = jQuery("#test-table").show().css("display") !== "table";
430 jQuery("#test-table").remove();
439 "table" : old ? "block" : "table",
440 "thead" : old ? "block" : "table-header-group",
441 "tbody" : old ? "block" : "table-row-group",
442 "tr" : old ? "block" : "table-row",
443 "th" : old ? "block" : "table-cell",
444 "td" : old ? "block" : "table-cell",
446 "li" : old ? "block" : "list-item"
449 jQuery.each(test, function(selector, expected) {
450 var elem = jQuery(selector, "#show-tests").show();
451 equal( elem.css("display"), expected, "Show using correct display type for " + selector );
454 // Make sure that showing or hiding a text node doesn't cause an error
455 jQuery("<div>test</div> text <span>test</span>").show().remove();
456 jQuery("<div>test</div> text <span>test</span>").hide().remove();
459 test("show() resolves correct default display #8099", function() {
461 var tt8099 = jQuery("<tt/>").appendTo("body"),
462 dfn8099 = jQuery("<dfn/>", { "html": "foo"}).appendTo("body");
464 equal( tt8099.css("display"), "none", "default display override for all tt" );
465 equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
467 equal( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
469 equal( tt8099.hide().css("display"), "none", "default display override for all tt" );
470 equal( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
472 equal( dfn8099.css("display"), "none", "default display override for all dfn" );
473 equal( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" );
479 test( "show() resolves correct default display for detached nodes", function(){
482 var div, span, tr, trDisplay;
484 div = jQuery("<div class='hidden'>");
485 div.show().appendTo("#qunit-fixture");
486 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div is visible." );
488 div = jQuery("<div style='display: none'>");
489 div.show().appendTo("#qunit-fixture");
490 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div is visible." );
492 span = jQuery("<span class='hidden'/>");
493 span.show().appendTo("#qunit-fixture");
494 equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through stylesheets ) span has default display." );
496 span = jQuery("<span style='display: inline'/>");
497 span.show().appendTo("#qunit-fixture");
498 equal( span.css("display"), "inline", "Make sure a detached, pre-hidden( through inline style ) span has default display." );
500 div = jQuery("<div><div class='hidden'></div></div>").children("div");
501 div.show().appendTo("#qunit-fixture");
502 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through stylesheets ) div inside another visible div is visible." );
504 div = jQuery("<div><div style='display: none'></div></div>").children("div");
505 div.show().appendTo("#qunit-fixture");
506 equal( div.css("display"), "block", "Make sure a detached, pre-hidden( through inline style ) div inside another visible div is visible." );
508 div = jQuery("div.hidden");
510 equal( div.css("display"), "block", "Make sure a detached( through detach() ), pre-hidden div is visible." );
513 span = jQuery("<span>");
514 span.appendTo("#qunit-fixture").detach().show().appendTo("#qunit-fixture" );
515 equal( span.css("display"), "inline", "Make sure a detached( through detach() ), pre-hidden span has default display." );
518 div = jQuery("<div>");
519 div.show().appendTo("#qunit-fixture");
520 ok( !!div.get( 0 ).style.display, "Make sure not hidden div has a inline style." );
523 div = jQuery( document.createElement("div") );
524 div.show().appendTo("#qunit-fixture");
525 equal( div.css("display"), "block", "Make sure a pre-created element has default display." );
528 div = jQuery("<div style='display: inline'/>");
529 div.show().appendTo("#qunit-fixture");
530 equal( div.css("display"), "inline", "Make sure that element has same display when it was created." );
533 tr = jQuery("<tr/>");
534 jQuery("#table").append( tr );
535 trDisplay = tr.css( "display" );
536 tr.detach().hide().show();
538 equal( tr[ 0 ].style.display, trDisplay, "For detached tr elements, display should always be like for attached trs" );
541 span = jQuery("<span/>").hide().show();
542 equal( span[ 0 ].style.display, "inline", "For detached span elements, display should always be inline" );
546 test("show() resolves correct default display #10227", function() {
549 var body = jQuery("body");
551 "<p id='ddisplay'>a<style>body{display:none}</style></p>"
554 equal( body.css("display"), "none", "Initial display: none" );
557 equal( body.css("display"), "block", "Correct display: block" );
559 jQuery("#ddisplay").remove();
560 QUnit.expectJqData( body[0], "olddisplay" );
563 test("show() resolves correct default display when iframe display:none #12904", function() {
566 var ddisplay = jQuery(
567 "<p id='ddisplay'>a<style>p{display:none}iframe{display:none !important}</style></p>"
570 equal( ddisplay.css("display"), "none", "Initial display: none" );
573 equal( ddisplay.css("display"), "block", "Correct display: block" );
578 test("toggle()", function() {
583 ok( x.is(":visible"), "is visible" );
585 ok( x.is(":hidden"), "is hidden" );
587 ok( x.is(":visible"), "is visible again" );
590 ok( x.is(":visible"), "is visible" );
592 ok( x.is(":hidden"), "is hidden" );
594 ok( x.is(":visible"), "is visible again" );
596 div = jQuery("<div style='display:none'><div></div></div>").appendTo("#qunit-fixture");
598 strictEqual( x.toggle().css( "display" ), "none", "is hidden" );
599 strictEqual( x.toggle().css( "display" ), "block", "is visible" );
601 // Ensure hide() is called when toggled (#12148)
602 oldHide = jQuery.fn.hide;
603 jQuery.fn.hide = function() {
604 ok( true, name + " method called on toggle" );
605 return oldHide.apply( this, arguments );
607 x.toggle( name === "show" );
608 jQuery.fn.hide = oldHide;
611 test("hide hidden elements (bug #7141)", function() {
615 var div = jQuery("<div style='display:none'></div>").appendTo("#qunit-fixture");
616 equal( div.css("display"), "none", "Element is hidden by default" );
618 ok( !jQuery._data(div, "olddisplay"), "olddisplay is undefined after hiding an already-hidden element" );
620 equal( div.css("display"), "block", "Show a double-hidden element" );
625 test("jQuery.css(elem, 'height') doesn't clear radio buttons (bug #1095)", function () {
628 var $checkedtest = jQuery("#checkedtest");
629 jQuery.css($checkedtest[0], "height");
631 ok( jQuery("input[type='radio']", $checkedtest).first().attr("checked"), "Check first radio still checked." );
632 ok( !jQuery("input[type='radio']", $checkedtest).last().attr("checked"), "Check last radio still NOT checked." );
633 ok( jQuery("input[type='checkbox']", $checkedtest).first().attr("checked"), "Check first checkbox still checked." );
634 ok( !jQuery("input[type='checkbox']", $checkedtest).last().attr("checked"), "Check last checkbox still NOT checked." );
637 test("internal ref to elem.runtimeStyle (bug #7608)", function () {
642 jQuery("#foo").css( { "width": "0%" } ).css("width");
647 ok( result, "elem.runtimeStyle does not throw exception" );
650 test("marginRight computed style (bug #3333)", function() {
653 var $div = jQuery("#foo");
659 equal($div.css("marginRight"), "0px", "marginRight correctly calculated with a width and display block");
662 test("box model properties incorrectly returning % instead of px, see #10639 and #12088", function() {
665 var container = jQuery("<div/>").width( 400 ).appendTo("#qunit-fixture"),
666 el = jQuery("<div/>").css({ "width": "50%", "marginRight": "50%" }).appendTo( container ),
667 el2 = jQuery("<div/>").css({ "width": "50%", "minWidth": "300px", "marginLeft": "25%" }).appendTo( container );
669 equal( el.css("marginRight"), "200px", "css('marginRight') returning % instead of px, see #10639" );
670 equal( el2.css("marginLeft"), "100px", "css('marginLeft') returning incorrect pixel value, see #12088" );
673 test("jQuery.cssProps behavior, (bug #8402)", function() {
676 var div = jQuery( "<div>" ).appendTo(document.body).css({
677 "position": "absolute",
681 jQuery.cssProps.top = "left";
682 equal( div.css("top"), "10px", "the fixed property is used when accessing the computed style");
683 div.css("top", "100px");
684 equal( div[0].style.left, "100px", "the fixed property is used when setting the style");
685 // cleanup jQuery.cssProps
686 jQuery.cssProps.top = undefined;
689 test("widows & orphans #8936", function () {
691 var $p = jQuery("<p>").appendTo("#qunit-fixture");
693 if ( "widows" in $p[0].style ) {
700 equal( $p.css("widows") || jQuery.style( $p[0], "widows" ), 0, "widows correctly start with value 0");
701 equal( $p.css("orphans") || jQuery.style( $p[0], "orphans" ), 0, "orphans correctly start with value 0");
708 equal( $p.css("widows") || jQuery.style( $p[0], "widows" ), 3, "widows correctly set to 3");
709 equal( $p.css("orphans") || jQuery.style( $p[0], "orphans" ), 3, "orphans correctly set to 3");
713 ok( true, "jQuery does not attempt to test for style props that definitely don't exist in older versions of IE");
720 test("can't get css for disconnected in IE<9, see #10254 and #8388", function() {
724 span = jQuery( "<span/>" ).css( "background-image", "url(data/1x1.jpg)" );
725 notEqual( span.css( "background-image" ), null, "can't get background-image in IE<9, see #10254" );
727 div = jQuery( "<div/>" ).css( "top", 10 );
728 equal( div.css( "top" ), "10px", "can't get top in IE<9, see #8388" );
731 test("can't get background-position in IE<9, see #10796", function() {
732 var div = jQuery( "<div/>" ).appendTo( "#qunit-fixture" ),
748 for( ; i < l; i++ ) {
749 div.css( "background-position", units [ i ] );
750 ok( div.css( "background-position" ), "can't get background-position in IE<9, see #10796" );
754 test("percentage properties for bottom and right in IE<9 should not be incorrectly transformed to pixels, see #11311", function() {
756 var div = jQuery("<div style='position: absolute; width: 1px; height: 20px; bottom:50%;'></div>").appendTo( "#qunit-fixture" );
757 ok( window.getComputedStyle || div.css( "bottom" ) === "50%", "position properties get incorrectly transformed in IE<8, see #11311" );
760 if ( jQuery.fn.offset ) {
761 test("percentage properties for left and top should be transformed to pixels, see #9505", function() {
763 var parent = jQuery("<div style='position:relative;width:200px;height:200px;margin:0;padding:0;border-width:0'></div>").appendTo( "#qunit-fixture" ),
764 div = jQuery("<div style='position: absolute; width: 20px; height: 20px; top:50%; left:50%'></div>").appendTo( parent );
766 equal( div.css("top"), "100px", "position properties not transformed to pixels, see #9505" );
767 equal( div.css("left"), "100px", "position properties not transformed to pixels, see #9505" );
771 test("Do not append px (#9548, #12990)", function() {
774 var $div = jQuery("<div>").appendTo("#qunit-fixture");
776 $div.css( "fill-opacity", 1 );
777 equal( $div.css("fill-opacity"), 1, "Do not append px to 'fill-opacity'" );
779 $div.css( "column-count", 1 );
780 if ( $div.css("column-count") ) {
781 equal( $div.css("column-count"), 1, "Do not append px to 'column-count'" );
783 ok( true, "No support for column-count CSS property" );
787 test("css('width') and css('height') should respect box-sizing, see #11004", function() {
790 // Support: Firefox, Android 2.3 (Prefixed box-sizing versions).
791 var el_dis = jQuery("<div style='width:300px;height:300px;margin:2px;padding:2px;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;'>test</div>"),
792 el = el_dis.clone().appendTo("#qunit-fixture");
794 equal( el.css("width"), el.css("width", el.css("width")).css("width"), "css('width') is not respecting box-sizing, see #11004");
795 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");
796 equal( el.css("height"), el.css("height", el.css("height")).css("height"), "css('height') is not respecting box-sizing, see #11004");
797 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");
800 test("certain css values of 'normal' should be convertable to a number, see #8627", function() {
803 var el = jQuery("<div style='letter-spacing:normal;font-weight:normal;'>test</div>").appendTo("#qunit-fixture");
805 ok( jQuery.isNumeric( parseFloat( el.css("letterSpacing") ) ), "css('letterSpacing') not convertable to number, see #8627" );
806 ok( jQuery.isNumeric( parseFloat( el.css("fontWeight") ) ), "css('fontWeight') not convertable to number, see #8627" );
809 // only run this test in IE9
810 if ( document.documentMode === 9 ) {
811 test( ".css('filter') returns a string in IE9, see #12537", 1, function() {
812 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')." );
816 test( "cssHooks - expand", function() {
820 margin: [ "marginTop", "marginRight", "marginBottom", "marginLeft" ],
821 borderWidth: [ "borderTopWidth", "borderRightWidth", "borderBottomWidth", "borderLeftWidth"],
822 padding: [ "paddingTop", "paddingRight", "paddingBottom", "paddingLeft" ]
825 jQuery.each( properties, function( property, keys ) {
826 var hook = jQuery.cssHooks[ property ],
828 jQuery.each( keys, function( _, key ) {
829 expected[ key ] = 10;
831 result = hook.expand( 10 );
832 deepEqual( result, expected, property + " expands properly with a number" );
834 jQuery.each( keys, function( _, key ) {
835 expected[ key ] = "10px";
837 result = hook.expand( "10px" );
838 deepEqual( result, expected, property + " expands properly with '10px'" );
840 expected[ keys[1] ] = expected[ keys[3] ] = "20px";
841 result = hook.expand( "10px 20px" );
842 deepEqual( result, expected, property + " expands properly with '10px 20px'" );
844 expected[ keys[2] ] = "30px";
845 result = hook.expand( "10px 20px 30px" );
846 deepEqual( result, expected, property + " expands properly with '10px 20px 30px'" );
848 expected[ keys[3] ] = "40px";
849 result = hook.expand( "10px 20px 30px 40px" );
850 deepEqual( result, expected, property + " expands properly with '10px 20px 30px 40px'" );
856 test( "css opacity consistency across browsers (#12685)", function() {
860 fixture = jQuery("#qunit-fixture");
862 // Append style element
863 jQuery("<style>.opacityWithSpaces_t12685 { opacity: 0.1; filter: alpha(opacity = 10); } .opacityNoSpaces_t12685 { opacity: 0.2; filter: alpha(opacity=20); }</style>").appendTo( fixture );
865 el = jQuery("<div class='opacityWithSpaces_t12685'></div>").appendTo(fixture);
867 equal( Math.round( el.css("opacity") * 100 ), 10, "opacity from style sheet (filter:alpha with spaces)" );
868 el.removeClass("opacityWithSpaces_t12685").addClass("opacityNoSpaces_t12685");
869 equal( Math.round( el.css("opacity") * 100 ), 20, "opacity from style sheet (filter:alpha without spaces)" );
870 el.css( "opacity", 0.3 );
871 equal( Math.round( el.css("opacity") * 100 ), 30, "override opacity" );
872 el.css( "opacity", "" );
873 equal( Math.round( el.css("opacity") * 100 ), 20, "remove opacity override" );
876 test( ":visible/:hidden selectors", function() {
879 ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible" );
880 jQuery("#nothiddendiv").css({ display: "none" });
881 ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden" );
882 jQuery("#nothiddendiv").css({"display": "block"});
883 ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
884 ok( jQuery(window).is(":visible") || true, "Calling is(':visible') on window does not throw an exception (#10267)");
885 ok( jQuery(document).is(":visible") || true, "Calling is(':visible') on document does not throw an exception (#10267)");
887 ok( jQuery("#nothiddendiv").is(":visible"), "Modifying CSS display: Assert element is visible");
888 jQuery("#nothiddendiv").css("display", "none");
889 ok( !jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is hidden");
890 jQuery("#nothiddendiv").css("display", "block");
891 ok( jQuery("#nothiddendiv").is(":visible"), "Modified CSS display: Assert element is visible");
893 // ok( !jQuery("#siblingspan").is(":visible"), "Span with no content not visible (#13132)" );
894 // var $newDiv = jQuery("<div><span></span></div>").appendTo("#qunit-fixture");
895 // equal( $newDiv.find(":visible").length, 0, "Span with no content not visible (#13132)" );
896 // var $br = jQuery("<br/>").appendTo("#qunit-fixture");
897 // ok( !$br.is(":visible"), "br element not visible (#10406)");
899 var $table = jQuery("#table");
900 $table.html("<tr><td style='display:none'>cell</td><td>cell</td></tr>");
901 equal(jQuery("#table td:visible").length, 1, "hidden cell is not perceived as visible (#4512). Works on table elements");
902 $table.css("display", "none").html("<tr><td>cell</td><td>cell</td></tr>");
903 equal(jQuery("#table td:visible").length, 0, "hidden cell children not perceived as visible (#4512)");
905 t( "Is Visible", "#qunit-fixture div:visible:lt(2)", ["foo", "nothiddendiv"] );
906 t( "Is Not Hidden", "#qunit-fixture:hidden", [] );
907 t( "Is Hidden", "#form input:hidden", ["hidden1","hidden2"] );
910 asyncTest( "Clearing a Cloned Element's Style Shouldn't Clear the Original Element's Style (#8908)", 24, function() {
911 var baseUrl = document.location.href.replace( /([^\/]*)$/, "" ),
913 name: "backgroundAttachment",
915 expected: [ "scroll" ]
917 name: "backgroundColor",
918 value: [ "rgb(255, 0, 0)", "rgb(255,0,0)", "#ff0000" ],
919 expected: ["transparent"]
921 // Firefox returns auto's value
922 name: "backgroundImage",
923 value: [ "url('test.png')", "url(" + baseUrl + "test.png)", "url(\"" + baseUrl + "test.png\")" ],
924 expected: [ "none", "url(\"http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif\")" ]
926 name: "backgroundPosition",
928 expected: [ "0% 0%", "-1000px 0px", "-1000px 0%" ]
930 // Firefox returns no-repeat
931 name: "backgroundRepeat",
933 expected: [ "repeat", "no-repeat" ]
935 name: "backgroundClip",
936 value: ["padding-box"],
937 expected: ["border-box"]
939 name: "backgroundOrigin",
940 value: ["content-box"],
941 expected: ["padding-box"]
943 name: "backgroundSize",
944 value: ["80px 60px"],
945 expected: [ "auto auto" ]
948 jQuery.each(styles, function( index, style ) {
949 var $clone, $clonedChildren,
950 $source = jQuery( "#firstp" ),
951 source = $source[ 0 ],
952 $children = $source.children();
954 style.expected = style.expected.concat( [ "", "auto" ] );
956 if ( source.style[ style.name ] === undefined ) {
957 ok( true, style.name + ": style isn't supported and therefore not an issue" );
963 $source.css( style.name, style.value[ 0 ] );
964 $children.css( style.name, style.value[ 0 ] );
966 $clone = $source.clone();
967 $clonedChildren = $clone.children();
969 $clone.css( style.name, "" );
970 $clonedChildren.css( style.name, "" );
972 window.setTimeout(function() {
973 notEqual( $clone.css( style.name ), style.value[ 0 ], "Cloned css was changed" );
975 ok( jQuery.inArray( $source.css( style.name ) !== -1, style.value ),
976 "Clearing clone.css() doesn't affect source.css(): " + style.name +
977 "; result: " + $source.css( style.name ) +
978 "; expected: " + style.value.join( "," ) );
980 ok( jQuery.inArray( $children.css( style.name ) !== -1, style.value ),
981 "Clearing clonedChildren.css() doesn't affect children.css(): " + style.name +
982 "; result: " + $children.css( style.name ) +
983 "; expected: " + style.value.join( "," ) );
987 window.setTimeout( start, 1000 );
990 asyncTest( "Make sure initialized display value for disconnected nodes is correct (#13310)", 4, function() {
991 var display = jQuery("#display").css("display"),
992 div = jQuery("<div/>");
994 equal( div.css( "display", "inline" ).hide().show().appendTo("body").css( "display" ), "inline", "Initialized display value has returned" );
997 div.css( "display", "none" ).hide();
998 equal( jQuery._data( div[ 0 ], "olddisplay" ), undefined, "olddisplay is undefined after hiding a detached and hidden element" );
1001 div.css( "display", "inline-block" ).hide().appendTo("body").fadeIn(function() {
1002 equal( div.css( "display" ), "inline-block", "Initialized display value has returned" );
1008 equal( jQuery._data( jQuery("#display").css( "display", "inline" ).hide()[ 0 ], "olddisplay" ), display,
1009 "display: * !Important value should used as initialized display" );
1010 jQuery._removeData( jQuery("#display")[ 0 ] );
1014 // We have to jump through the hoops here in order to test work with "order" CSS property,
1015 // that some browsers do not support. This test is not, strictly speaking, correct,
1016 // but it's the best that we can do.
1018 var style = document.createElement( "div" ).style,
1019 exist = "order" in style || "WebkitOrder" in style;
1022 test( "Don't append px to CSS \"order\" value (#14049)", 1, function() {
1023 var $elem = jQuery( "<div/>" );
1025 $elem.css( "order", 2 );
1026 equal( $elem.css( "order" ), "2", "2 on order" );