Bug Tracker

Ticket #14750 (closed bug: fixed)

Opened 7 months ago

Last modified 5 months ago

$.show() after $.hide() sometimes does not restore the correct display style

Reported by: jd Owned by: markelog
Priority: low Milestone: 1.11.1/2.1.1
Component: css Version: 2.1.0
Keywords: Cc:
Blocking: Blocked by:

Description

The docs of $.show() state:
"With no parameters, ... the matched elements will be revealed immediately, with no animation. This is roughly equivalent to calling .css('display', 'block'), except that the display property is restored to whatever it was initially. If an element has a display value of inline, then is hidden and shown, it will once again be displayed inline."

The implementation in function showHide(elements, show) uses a data_priv variable "olddisplay" to remember the old display when hiding elements. This variable is then used to restore the display property when elements are shown.

The current implementation only sets "olddisplay" once in the first call to hide(), and then restores the display using that value in all subsequent calls to show(). If after the first call to hide() the display property was set to another value, then show() will restore display to the unwanted old value.

I illustrated the bug in  http://jsfiddle.net/6XG8u/6/

To work correctly showHide() should always store the current display property when hiding elements.

Change History

comment:1 Changed 7 months ago by dmethvin

  • Owner set to jd
  • Status changed from new to pending

So the behavior is documented, and to be expected. What resolution would you suggest for this bug?

comment:2 Changed 7 months ago by jd

  • Status changed from pending to new

As suggested the JQuery implementation function showHide() should always store the current display property when hiding elements.

Right now it stores the display property only in the first call to hide().

comment:3 Changed 7 months ago by markelog

  • Owner changed from jd to markelog
  • Priority changed from undecided to low
  • Status changed from new to assigned
  • Component changed from unfiled to css

Change is trivial and it would saves some bytes

comment:4 Changed 6 months ago by fpagano1986@…

Hi, This anomaly is very impactful and creates many problems on each element on which this method is invoked (in my project many case histories are skipped). Set the CSS display property to "inline-block" without taking into account the old value can create many side effects. Assume that this element should be considered as a block, but compared to other inline elements do not seem to be correct. Also, in my opinion, you should increase the priority for this bug so that it can be resolved shortly. Thanks for your attention, I hope for a quick resolution of your problem.

comment:5 Changed 6 months ago by cat

Furthermore jQuery 1.11 on ie8 adds zoom:1 css style, and I had to come back to old jQuery version. I think this bug is very dangerous so I suggest you to set ticket's priority to blocker!!!

comment:6 Changed 5 months ago by dmethvin

  • Milestone changed from None to 1.11.1/2.1.1

comment:7 Changed 5 months ago by Oleg Gaidarenko

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

CSS: jQuery#hide should always save display value

Fixes #14750 Closes gh-1509

Changeset: 5a8f76933288396b915800a18240aa17d3414201

Note: See TracTickets for help on using tickets.