Skip to main content

Bug Tracker

Side navigation

#11790 closed bug (worksforme)

Opened May 21, 2012 03:36AM UTC

Closed May 21, 2012 04:17AM UTC

Last modified October 14, 2012 01:11PM UTC

<li> .clone(), .show() .appendTo() force-sets display to list-item

Reported by: lautaro.dragan@gmail.com Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.7.2
Keywords: Cc:
Blocked by: Blocking:
Description

See http://jsfiddle.net/BHCcy/2/

Tested in

-Firefox 12

-Chrome 19.0.1084.46 m

-Safari 5.1.7

Not sure if bug or feature (insert fry here), but this didn't happen in 1.7.1.

Attachments (0)
Change History (5)

Changed May 21, 2012 03:39AM UTC by anonymous comment:1

http://jsfiddle.net/BHCcy/4/

Replying to [ticket:11790 lautaro.dragan@…]:

See http://jsfiddle.net/BHCcy/2/ Tested in -Firefox 12 -Chrome 19.0.1084.46 m -Safari 5.1.7 Not sure if bug or feature (insert fry here), but this didn't happen in 1.7.1.

Changed May 21, 2012 04:17AM UTC by mikesherov comment:2

resolution: → worksforme
status: newclosed

If you call show on an item that isn't yet appended to the DOM, it will set the display value to whatever the default display for that element is. This is correct behavior and is a feature.

Changed October 13, 2012 05:39PM UTC by rnortman comment:3

Replying to [comment:2 mikesherov]:

If you call show on an item that isn't yet appended to the DOM, it will set the display value to whatever the default display for that element is. This is correct behavior and is a feature.

Why is this a desirable feature? It is causing me substantial headaches, because then it overrides whatever is in my stylesheets for the element. My application often calls show/hide for elements not currently in the DOM. I could certainly redesign it not to, but why?

Why not set display to the empty string instead of setting it to the browser default? That avoids overriding stylesheets. (This is a change in behavior since jQuery 1.6, which my app was originally developed against.)

Changed October 14, 2012 12:52AM UTC by mikesherov comment:4

rnortman, what if you have a style rule like:

li {
display: none;
}

Setting display to empty string here doesn't show the element, to answer your question.

When an element is not appended, it is not part of the cascade, and there is no way to know that it'll eventually be appended to the set of elements that are inline-block. and not list-item.

Changed October 14, 2012 01:11PM UTC by rnortman comment:5

That makes sense, and after submitting my comment I ran into exactly that problem when I tried to monkey-patch jQuery to have the behavior I wanted, and ended up breaking the datepicker (which sets display: none in its CSS).

I would suggest updating the documentation of show/hide to make it clear that the behavior may be surprising if used on elements not currently part of the DOM. Or alternately, make those functions unwilling to operate on elements not in the DOM (make it a no-op with a warning logged). For my application, I am going to have to quit using JQ's show/hide and make my own routines instead -- or else re-factor the code to execute the show/hide after the elements get added to the DOM (which makes things more complicated).