var elem = jQuery( "<" + nodeName + ">" ).appendTo( "body" ),
display = elem.css( "display" );
- elem.remove();
+ elem.remove();
if ( display === "none" || display === "" ) {
+ // Get element's real default display by attaching it to a temp iframe
+ // Conritbutions from Louis Remi and Julian Aurbourg
+ // based on recommendation by Louis Remi
+
// No iframe to use yet, so create it
if ( !iframe ) {
-
iframe = document.createElement( "iframe" );
- iframe.width = iframe.height = 0;
+ iframe.frameBorder = iframe.width = iframe.height = 0;
+ }
- document.body.appendChild( iframe );
+ document.body.appendChild( iframe );
+ // Create a cacheable copy of the iframe document on first call.
+ // IE and Opera will allow us to reuse the iframeDoc without re-writing the fake html
+ // document to it, Webkit & Firefox won't allow reusing the iframe document
+ if ( !iframeDoc || !iframe.createElement ) {
iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document;
- iframeDoc.write("<!doctype><html><body></body></html>");
-
- } else {
-
- // Reuse previous iframe
- document.body.appendChild( iframe );
-
+ iframeDoc.write( "<!doctype><html><body></body></html>" );
}
elem = iframeDoc.createElement( nodeName );
iframeDoc.body.appendChild( elem );
- display = jQuery( elem ).css( "display" );
+ display = jQuery.css( elem, "display" );
- iframe.parentNode.removeChild( iframe );
+ document.body.removeChild( iframe );
}
// Store the correct default display
test("show() resolves correct default display #8099", function() {
expect(7);
- var bug8099 = jQuery("<tt/>").appendTo("#main"),
- div8099 = jQuery("<div/>", { className: "hidden" }).appendTo("#main");
+ var tt8099 = jQuery("<tt/>").appendTo("body"),
+ dfn8099 = jQuery("<dfn/>", { html: "foo"}).appendTo("body");
- equals( bug8099.css("display"), "none", "default display override for all tt" );
- equals( bug8099.show().css("display"), "inline", "Correctly resolves display:inline" );
+ equals( tt8099.css("display"), "none", "default display override for all tt" );
+ equals( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
equals( jQuery("#foo").hide().show().css("display"), "block", "Correctly resolves display:block after hide/show" );
- equals( bug8099.hide().css("display"), "none", "default display override for all tt" );
- equals( bug8099.show().css("display"), "inline", "Correctly resolves display:inline" );
+ equals( tt8099.hide().css("display"), "none", "default display override for all tt" );
+ equals( tt8099.show().css("display"), "inline", "Correctly resolves display:inline" );
- equals( div8099.show().css("display"), "block", "default display override for all div.hidden" );
- equals( div8099.hide().css("display"), "none", "Correctly resolves display:none" );
+ equals( dfn8099.css("display"), "none", "default display override for all dfn" );
+ equals( dfn8099.show().css("display"), "inline", "Correctly resolves display:inline" );
- bug8099.remove();
- div8099.remove();
+ tt8099.remove();
+ dfn8099.remove();
});