When clicked, check if the div is open, if false - open with .show, if true do nothing

I use jquery .showto open div. This works fine for me, but I have a bit of a development problem, how to get it to check if it is open div. If so, I do not want it to repeat the function .show. What is the best way to do this?

I am currently using (jquery + jquery ui)

$(document).ready(function() {
$('.content').hide(); 

$(".open").click(function () {
  $(".content").show("slide", { direction: "up" },1200);
});

$(".close").click(function () {
  $(".content").hide("slide", { direction: "up" },1200);
});

}); 
+3
source share
2 answers

You can use : visible selector and : hidden selector

$(document).ready(function() {
    $('.content').hide();
    $(".open").click(function () {
        $(".content:hidden").show("slide", { direction: "up" }, 1200);
    });
    $(".close").click(function () {
        $(".content:visible").hide("slide", { direction: "up" }, 1200);
    });
});

Also see my example .

+2
source
if ($(".content").is(":visible") {
    // it is showing already
} ...

http://api.jquery.com/slideToggle/

¡¡¡ !!!

+3

All Articles