visibility:visible/hidden div

Scott Robertson picture Scott Robertson · May 1, 2012 · Viewed 94.1k times · Source

What is the best way to show a div when clicked on a button and then hide it with a close button??

My Jquery code is as follows:

$(".imageIcon").click(function(){
$('.imageShowWrapper').css("visibility", 'visible');
});
 $(".imageShowWrapper").click(function(){
$('.imageShowWrapper').css("visibility", 'hidden');
});

except the problem I'm having is it closes automatically without any clicks. It loads everything ok, displays for about 1/2 sec and then closes. Any ideas?

Answer

undefined picture undefined · May 1, 2012

You can use the show and hide methods:

$(".imageIcon").click(function() {
    $('.imageShowWrapper').show();
});

$(".imageShowWrapper").click(function() {
    $(this).hide();
});