Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPAN element becomes block level on show() in jQuery

Tags:

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

like image 258
Šime Vidas Avatar asked Jan 31 '11 17:01

Šime Vidas


2 Answers

That's a bug, right. But you can do $('span').css('display', 'inline'); rather than $('span').show();

like image 150
JacopKane Avatar answered Oct 31 '22 14:10

JacopKane


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

like image 21
Mordi Avatar answered Oct 31 '22 15:10

Mordi