jQuery click / toggle between two functions

前端 未结 10 1541
野的像风
野的像风 2020-11-22 07:58

I am looking for a way to have two separate operations / functions / \"blocks of code\" run when something is clicked and then a totally different block when the same thing

10条回答
  •  抹茶落季
    2020-11-22 08:51

    I used this to create a toggle effect between two functions.

    var x = false;
    $(element).on('click', function(){
     if (!x){
      //function
      x = true;
     }
     else {
      //function
      x = false;
     }
    });
    

提交回复
热议问题