Satch3000 Satch3000 - 7 months ago 9
Javascript Question

JQuery hide does not remove the space of the object?

I am using some jQuery code where I hide a list item...

$("ul.items").each(function() {
$("li:gt(4)", this).hide();


My problem is that
.hide
seems to hide the element but the space for it is still allocated.

Is there a way to remove this space... like
display:none
on CSS does?

UPDATE:
.hide
is actually taking away the element but the other elements are not stretching up to take the missing space left by the element.

Answer

Hmm that shouldn't happen. $.fn.hide() sets display: none; not visibility: hidden; or opacity: 0; (which would hide the element but keep its space occupied).

"This is roughly equivalent to calling .css('display', 'none'), except that the value of the display property is saved in jQuery's data cache so that display can later be restored to its initial value" - from http://api.jquery.com/hide/.

Edit: Have you checked with Firebug (or similar) what actually happens to the element?