Jquery toggle using 2 elements

Posted by user801773 on Stack Overflow See other posts from Stack Overflow or by user801773
Published on 2011-11-11T17:41:37Z Indexed on 2011/11/11 17:51 UTC
Read the original article Hit count: 193

Filed under:
|
|
|
|

this is my script, I'm using a toggle so I can animate a sliding menu.

    $("div.show-menu").click().toggle(
        function() {
            // first alternation
            $("#slideover").animate({
                right: "512px"
                }, 300);
            $(".menu-button").html('close menu');


        }, function() {
            // second alternation
            $("#slideover").animate({
                right: "0"
                }, 300);
            $(".menu-button").html('open menu');

    });

Though I really need the toggle to work using 2 elements on the page. For example see below...

<div class="show-menu one">open menu</div> // this is element one

<div class="show-menu two">open menu</div> // this is element two

I need it so, if element one get's click first, you can close the menu using element two on the first click. What is happening now is that you have to click element two twice in order for it to close the menu - vice versa

I guess this is the toggle coming into play, any help would be great thanks.

Cheers Josh

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery