Youssef Youssef - 4 months ago 19
HTML Question

Hide div but keep the empty space

I have the following div

CSS

.description {
color: #b4afaf;
font-size: 10px;
font-weight: normal;
}


HTML

<div class="description">Some text here </div>


Then I have a click function on an element to hide the above div:

$('#target').click(function(){
$(".description").hide();
});


When I hide the div it will collapse (stop taking any space). This is messing with the layout of my page.

Is there a way I can hide the div but still take the space that it was taking before? I dont want to change the font color because it would be still selectable.

Thanks

Answer

Use visibility css property for this

visibility:

The visibility property specifies whether the boxes generated by an element are rendered.

$(".description").css('visibility', 'hidden');

Demo: Fiddle

Comments