Reputation: 277
I'm using the standard:
$(document).ready(function() {
$('#toggleme').click(function(){
$('div.#showhide').toggle();
});
$('#closer').click(function(){
$('div.#showhide').toggle();
});
});
To show and hide a div, but when the site is set to display:none;
the div disapears and all of my content moves up the page.
Is there a different way of showing/hiding the div, or should I wrap each div in a parent div with a fixed width/height?
Upvotes: 2
Views: 2482
Reputation: 22570
Maybe try this:
$(document).ready(function() {
$('#toggleme').toggle(function(){
$('.showhide').animate({ "height", "0px" });
},
function(){
$('.showhide').animate({ "height", "SomeBaseHeightpx" });
});
$('#closer').toggle(function(){
$('.showhide').animate({ "height", "0px" });
},
function(){
$('.showhide').animate({ "height", "SomeBaseHeightpx" });
});
});
Play with it some and adjust it to your HTML, but that should do exactly what you want.
See more at jQuery .animate() && jQuery .toggle() [event]
Upvotes: 0
Reputation: 699
You can use jQuery.show()
and jQuery.hide()
methods for showing and hiding the elements respectively.
Upvotes: 0
Reputation: 2407
Set visibility to hidden like this:
$('div.#showhide').css('visibility', 'hidden');
Show it again like this:
$('div.#showhide').css('visibility', 'visible');
Upvotes: 0
Reputation: 14575
CSS attribute visibility: hidden;
is what you want, it will hide it like display block but the space will still be there so no content moves.
Upvotes: 2
Reputation: 176886
make use of .show()
and hide()
method for that
.show() - Display the matched elements.
.hide() - Hide the matched elements.
or also try out
.toggle() - Display or hide the matched elements
Upvotes: 1