Bug Tracker

Opened 9 years ago

Closed 9 years ago

#14750 closed bug (fixed)

$.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:
Blocked by: Blocking:


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 (7)

comment:1 Changed 9 years ago by dmethvin

Owner: set to jd
Status: newpending

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

comment:2 Changed 9 years ago by jd

Status: pendingnew

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 9 years ago by markelog

Component: unfiledcss
Owner: changed from jd to markelog
Priority: undecidedlow
Status: newassigned

Change is trivial and it would saves some bytes

comment:4 Changed 9 years 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 9 years 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 9 years ago by dmethvin

Milestone: None1.11.1/2.1.1

comment:7 Changed 9 years ago by Oleg Gaidarenko

Resolution: fixed
Status: assignedclosed

CSS: jQuery#hide should always save display value

Fixes #14750 Closes gh-1509

Changeset: 5a8f76933288396b915800a18240aa17d3414201

Note: See TracTickets for help on using tickets.