Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

on click, check if div is open, if false - open using .show, if true do nothing

I'm using jquery .show to open a div. I've got it working fine but I'm having a bit of trouble working out how to get it to check if the div's already open. If it is, I don't want it to repeat the .show function. What's the best way to do this?

What I'm using at the moment is (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);
});

}); 
like image 448
sam Avatar asked Nov 29 '25 16:11

sam


1 Answers

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

You might also look at http://api.jquery.com/slideToggle/

¡¡¡FUN EXAMPLES HERE!!!

like image 171
SpYk3HH Avatar answered Dec 02 '25 07:12

SpYk3HH



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!