Fatih Toprak
Fatih Toprak

Reputation: 1007

do something after second click?

Here is my dropdown menu code samples.

    $( document ).ready(function() {
       $('.collapsedArchives ul li').click(function(){
            $('.collapsedArchives ul li ul').slideDown('slow');
       });
       $('.collapsedArchives ul li ul').click(function(){
            $('.collapsedArchives ul li ul li').slideDown('slow');
       });
    });

What should id do, using slideUp animation when user click slideDown's selectors click 2nd time ?

Thanks.

Upvotes: 2

Views: 111

Answers (3)

user2517028
user2517028

Reputation: 844

I didn't really understand the question clearly, but from the answers provided I guess you can use this, this will allow you to open/close the li ul and leave the other elements on their current state open or cloesed

$('.collapsedArchives ul li').click(function () {
    $(this).find("ul").slideToggle('slow');
});

but I guess for a drop down you might want to close all other il ul which is other than the one you just clicked:

$('.collapsedArchives ul li').click(function () {
    $(".collapsedArchives ul li ul").slideUp('slow');
    $(this).find("ul").slideDown('slow');
});

check this demo

Upvotes: 1

epascarello
epascarello

Reputation: 207547

jQuery has .slideToggle( \[duration \] \[, complete \] )

$('.collapsedArchives ul li').click(function(){
    $(this).find('> ul').slideToggle('slow');
});

Now you want to probably cancel the bubbling of the click also with event.stopPropagation()

$('.collapsedArchives ul li').click(function(evt){
    evt.stopPropagation();
    $(this).find('> ul').slideToggle('slow');
});

Upvotes: 2

Fallenreaper
Fallenreaper

Reputation: 10704

An alternate option would be to store a variable in the object

$(item).data("somevar", true);

which you can check against, flip depending on the case and then have conditional which routes what happens.

Upvotes: 1

Related Questions