BigJobbies
BigJobbies

Reputation: 4045

jQuery - Checking to see what state the slideToggle is in

I'm not a very good jQuery coder. Actually I'm new and terrible and I was wondering if someone could help me out.

I have a bunch of divs which I'm using slideToggle on to display options. The code I have at the moment works. But I want to do when someone clicks the link is to check to see if there are any 'open' slidetoggles. If there are, close them and just open the one that i clicked on.

I'm sure my current code is not good, so any help on cleaning it up and adding this functionality would be greatly appreciated.

The code is as follows:

<script type="text/javascript">
jQuery(document).ready(function(){
    jQuery("#parent-print").click(function(e) {
        jQuery("#child-print").slideToggle();
        e.preventDefault();
    });

    jQuery("#parent-web").click(function(e) {
        jQuery("#child-web").slideToggle();
        e.preventDefault();
    });

    jQuery("#parent-inspiration").click(function(e) {
        jQuery("#child-inspiration").slideToggle();
        e.preventDefault();
    });
});
</script>

Thank you

Upvotes: 1

Views: 2164

Answers (1)

RRikesh
RRikesh

Reputation: 14381

Have you tried this?

if( jQuery('#parent-web').is(':hidden') ){..}

http://api.jquery.com/hidden-selector/

Upvotes: 2

Related Questions