tags:

views:

34

answers:

2

I've got a div#items and if it's clicked then div#choices slideDown(). If it's clicked again then div#choices should slideUp(); How can I test if choices is down or up already? I know I could store in a variable and toggle it's value whenever div#items is clicked, but what if #choices has been slid down by other means?

+2  A: 

Use .slideToggle()

Marimuthu Madasamy
Won't work since he said the slide can be performed by other elements.
Kaaviar
+1. @Kaaviar: actually, this should work well enough because `slideToggle()` will check to see if the element is currently hidden or shown.
Andy E
+3  A: 

As Marimuthu's answer points out, you can use slideToggle() to slide up if the div is already open, or down if it's closed.

You can also check the display property to find out if it's currently visible or not. From the jQuery docs for slideUp().

Once the height reaches 0, the display style property is set to none to ensure that the element no longer affects the layout of the page.

Knowing this, you can check to see if it is set to "none":

var $choices = $('div#choices');
if ($choices.css("display") == "none")
    $choices.slideDown();
else
    $choices.slideUp();
Andy E