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?
display = 'inline'; to make the div display inline with other elements. And we can write: const div = document.
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.
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.
You can use the show
and hide
methods:
$(".imageIcon").click(function() {
$('.imageShowWrapper').show();
});
$(".imageShowWrapper").click(function() {
$(this).hide();
});
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?
Another option:
$(".imageIcon, .imageShowWrapper").click(function() {
$(".imageShowWrapper").toggle($(this).hasClass('imageIcon'));
});
You can also use fadeToggle
and slideToggle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With