Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visibility:visible/hidden div

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?

like image 250
Scott Robertson Avatar asked May 01 '12 02:05

Scott Robertson


People also ask

How do I make a div visible?

display = 'inline'; to make the div display inline with other elements. And we can write: const div = document.

What is the difference between visible and hidden?

visible: It is used to specify the element to be visible. It is a default value. hidden: Element is not visible, but it affects layout.

What does visibility hidden do?

visibility:hidden means that unlike display:none, the tag is not visible, but space is allocated for it on the page. The tag is rendered, it just isn't seen on the page.


3 Answers

You can use the show and hide methods:

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

$(".imageShowWrapper").click(function() {
    $(this).hide();
});
like image 191
undefined Avatar answered Nov 07 '22 01:11

undefined


According to your requirement, I believe what you need is as simple as this: http://jsfiddle.net/linmic/6Yadu/

However, using the visibility is different from using show/hide function, gory details: What is the difference between visibility:hidden and display:none?

like image 44
Linmic Avatar answered Nov 07 '22 02:11

Linmic


Another option:

$(".imageIcon, .imageShowWrapper").click(function() {  
    $(".imageShowWrapper").toggle($(this).hasClass('imageIcon'));     
});

You can also use fadeToggle and slideToggle

like image 41
brains911 Avatar answered Nov 07 '22 01:11

brains911