Bug Tracker

Ticket #10227 (closed bug: fixed)

Opened 3 years ago

Last modified 15 months ago

$('body').show() does'nt work if body style is set to display:none

Reported by: Jürgen Owned by: rwaldron
Priority: low Milestone: 1.8.3
Component: css Version: git
Keywords: Cc: dmethvin
Blocking: Blocked by:

Description

Hi, i'm using jQuery 1.6.2 and $('body').show(); seems to fail if the style of BODY is set to display:none.

I used $('body').toggle() instead but with the same issue. Removing the display:none in the body-style lets work $('body').toggle() fine.

Best regards, Jürgen

Change History

comment:1 Changed 3 years ago by anonymous

if you need to use show() can set body { display:none; } in css style... tested on IE and Chrome...

for firefox i have to do this:

$(window).load(function(){

if($.browser.mozilla)

$('body').css('display','block');

$('body').fadeIn(100);

});

fadeIn() or show() will fail with FF if body is set to display:none...

comment:2 Changed 3 years ago by addyosmani

  • Cc dmethvin added
  • Priority changed from undecided to low
  • Status changed from new to open
  • Component changed from unfiled to css
  • Version changed from 1.6.2 to git

Confirmed:  http://jsfiddle.net/drCRZ/2/. Behaviour present in FF6 and below with jQuery edge and 1.6.3 but not in Chrome or IE. CC'ing dmethvin so he can weigh in on whether this is something we want to address.

comment:3 Changed 3 years ago by dmethvin

Confirmed, I am not seeing a problem on Windows with Chrome 13.0.782.220 m, IE 9.0.8112.16421, or Opera 11.51. I *do* see the problem on Firefox 6.0.2, but it goes away if you use bare JS ( http://jsfiddle.net/dmethvin/drCRZ/3/) or remove the display: none from the body style ( http://jsfiddle.net/dmethvin/drCRZ/4/).

I suspect things are getting muddled because of the display: none, why does it need to be there?

comment:4 Changed 3 years ago by timmywil

Things are muddled because defaultDisplay can't handle a body element for some reason (not sure why yet). Instead of being set to something workable, it is set to undefined, which means the display style just gets set to empty string, which does nothing to override the embedded style.  screenshot of breakpoint in defaultDisplay

comment:5 Changed 3 years ago by mikesherov

looks like defaultDisplay is trying to append the element you're trying to show() to body and then extract the display css attribute out of that. I'm guessing that certain browsers dont like appending a new body to a body.

PR for this should be relatively painless... i'm on it.

comment:6 Changed 3 years ago by mikesherov

hmm, or not... still a bit over my head with the iframe fallback.

comment:7 Changed 3 years ago by mikesherov

So, one question I need answered here... is there ever a reason that the defaultDisplay for a BODY tag shouldn't be "block"? I mean, how is a doc rendered different if BODY was "inline"?

If we always assume the defaultDisplay for a BODY tag is "block", this issue is very easily fixed. Otherwise, I have no idea what the hell is going on.

comment:8 Changed 3 years ago by mikesherov

figured it out... so basically, in FF, getComputedValue inside an IFRAME inherits the display of the outer frame.

If the BODY is display:none, than the IFRAME fallback gets appended to the hidden body, and all of the getComputedValue calls inside that IFRAME are display: none.

So this doesn't just effect body.show(), it affects .show() on any element that needs the IFRAME fallback if the BODY is hidden at the time of adding the IFRAME as a fallback.

Testing this was tons of fun... submitting PR now.

comment:10 Changed 3 years ago by mikesherov

  • Owner set to mikesherov
  • Status changed from open to assigned
  • Milestone changed from None to 1.7.2

comment:11 Changed 3 years ago by dmethvin

  • Keywords needsdocs added
  • Status changed from assigned to closed
  • Resolution set to wontfix

We're going to just document this.

comment:12 Changed 3 years ago by dmethvin

  • Keywords needsdocs removed
  • Status changed from closed to reopened
  • Resolution wontfix deleted

comment:13 Changed 3 years ago by dmethvin

  • Status changed from reopened to open

Mistake.

comment:14 Changed 3 years ago by dmethvin

  • Status changed from open to closed
  • Resolution set to wontfix

No, we are really closing this. To clarify it only breaks in FF 3.6.

comment:15 Changed 2 years ago by vladimir@…

This is still an issue in the latest Firefox versions; in trying to track it down I filed  https://bugzilla.mozilla.org/show_bug.cgi?id=797029 . bz's suggestion in comment 7 seems like it's worth trying -- basically, he's suggesting attaching the <iframe> as a child of the <html> element, and not <body>; that will avoid a display: none rule on body throwing things off. This seems to work fine; it correctly finds the default display of body as 'block' even when a display: none rule is in effect on body in the document.

Only change I made was body.appendElement/body.removeChild -> body.parentNode.appendElement/body.parentNode.removeChild in the defaultDisplay() function.

comment:16 Changed 2 years ago by rwaldron

  • Status changed from closed to reopened
  • Resolution wontfix deleted
  • Milestone 1.7.2 deleted

I'll give Boris's suggestion a try...

comment:17 Changed 2 years ago by rwaldron

  • Owner changed from mikesherov to rwaldron
  • Status changed from reopened to assigned

comment:18 Changed 2 years ago by rwaldron

  • Status changed from assigned to closed
  • Resolution set to worksforme

This issue doesn't exist in jQuery 1.8.x

comment:19 Changed 2 years ago by rwaldron

  • Status changed from closed to reopened
  • Resolution worksforme deleted

Just kidding, there was a bug in my test.

comment:20 Changed 2 years ago by Rick Waldron

  • Status changed from reopened to closed
  • Resolution set to fixed

body default display is always block. @mikesherov was right and this is the proof. Fixes #10227

Changeset: 60f546acb1c7136092b4fd01cccff052e468cc72

comment:21 Changed 2 years ago by dmethvin

  • Milestone set to 1.8.3

comment:22 Changed 15 months ago by Oleg

Fix #10227 and simplification and optmization of defaultDisplay helper

Changeset: 664d099f9d7e64a43e1e5423a343fdefa5be649f

Note: See TracTickets for help on using tickets.