Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hide element without setting the display to none in jquery

I want to fold a section of the form without setting its display to none. If i set the display to none, the validation is bypassed that is why I don't want to set the display to none. I know I can set the visibility to hidden and visible but this solution is not feasible for rendering the view as the space for the folded section stays there. This results in a very odd look of the view with an empty white space with no content on it.

So my question is to hide a section of the html form (without intacting a placeholder for it) without setting its display to none, so that I could still perform the validation.

Some HTML code:

<td style="margin: 5px; border-bottom: 1px solid; display:none; overflow: hidden;" colspan="3">
    <div>...</div>
</td>

The display is initially set to none but once it is unfolded for the first time, I am setting the height to 100% and removing the display style.

like image 269
Obaid Maroof Avatar asked Aug 27 '13 09:08

Obaid Maroof


Video Answer


1 Answers

You can move it off the screen:

$(elem).css("position", "absolute").css("left", -9999);

Or set it's height to 0:

$(elem).css("height", 0);
like image 81
CodingIntrigue Avatar answered Sep 21 '22 11:09

CodingIntrigue