Hide div but keep the empty space

Youssef picture Youssef · May 1, 2013 · Viewed 50.4k times · Source

I have the following div element:

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 collapses and stops taking up space. This messes up the layout of my page.

Is there a way to hide the div, but still maintain the space it was taking before? I don't want to change the font color because it would be still selectable.

Answer

Arun P Johny picture Arun P Johny · May 1, 2013

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