I just got a script to work by changing
$('#thisElement').show();
to
$('#thisElement').css({'display':'block'});
where #thisElement
had been loaded as having display:none;
Is there a fundamental difference in these two expressions?
I just got a script to work by changing
$('#thisElement').show();
to
$('#thisElement').css({'display':'block'});
where #thisElement
had been loaded as having display:none;
Is there a fundamental difference in these two expressions?
If you had hidden #thisElement
using $('#thisElement').hide();
, and it had a display
property that was not block
, show()
restores whatever the value was before you hid it.
Assuming you have this at the beginning:
<span id="thisElement" style="display: none;">Foo</span>
when you call:
$('#thisElement').show();
you will get:
<span id="thisElement" style="">Foo</span>
while:
$('#thisElement').css({'display':'block'});
does:
<span id="thisElement" style="display: block;">Foo</span>
so, yes there's a difference.
show()
allows for other display values, like inline
. From the documentation:
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.
From the jQuery show() documentation:
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.