Registering jQuery click, first and second click

前端 未结 9 899
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-29 23:23

Is there a way to run two functions similar to this:

$(\'.myClass\').click(
    function() {
        // First click
    },
    function() {
        // Second         


        
9条回答
  •  遥遥无期
    2020-11-29 23:52

    I reach here looking for some answers, and thanks to you guys I´ve solved this in great manner I would like to share mi solution.

    I only use addClass, removeClass and hasClass JQuery commands.

    This is how I´ve done it and it works great:

    $('.toggle').click(function() { 
                if($('.categ').hasClass("open")){
                    $('.categ').removeClass('open');
                }
                else{           
                    $('.categ').addClass('open');                                   
                }
            });
    

    This way a class .open is added to the Html when you first clikc. Second click checks if the class exists. If exists it removes it.

提交回复
热议问题