SPAN element becomes block level on show() in jQuery
I created two demos:
Demo 1: http://jsfiddle.net/DqvTa/7/
Demo 2: http://jsfiddle.net/DqvTa/8/The demos are almost identical. The only difference is that I set #span { display:none; }
in demo 1 and span { display:none; }
in demo 2.
Could someone explain why the SPAN element - in demo 2 - becomes a block-level element?
My assumption is that (during show()
) jQuery internally creates a SPAN element to check whether it is naturally an inline or block-level element. But since I set all 开发者_开发百科SPANs to display:none
in demo 2, jQuery is unable to determine that.
btw the ticket is here: http://bugs.jquery.com/ticket/8099
That's a bug, right.
But you can do $('span').css('display', 'inline');
rather than $('span').show();
This is because, .show(), is like a display block except that the display property is restored to whatever it was initially.
jQuery use a propertry called olddisplay in the node that you modify with show (you can see it with FireQuery), if you modify the box model of the span, (not the #span) jquery dont recognice the correct old display mode of the node
This issue has been identified as a bug. The ticket is here:
http://bugs.jquery.com/ticket/8099
精彩评论