How to reopen a closed click event in jQuery without reload?

97 Views Asked by At

I am trying to reopen a closed click event using jQuery but I don't want to refresh my page for it. For better understanding,please take a look at what I really want:

$(function (){
Var i = 0;
Var j =0;
$("#first").on("click" , function (){
i++;
});
$("#second").on("click" , function (){
j++;
});
if(i = j){
$("first").off("click");
}
$("#third").on("click" , function (){
alert("what should I write here to reopen #first ID closed click event, without any refresh or reload");
});
});

After I click my #third ID, I want my #first ID with closed click event to start responding again on click!

Edited |

Why I want to do this: I've to use off() , so that no one can add anything in the list given in my website, by clicking #first ID once the limit is exceeded, and can only be able to do so after removing previous list which is already full ...

1

There are 1 best solutions below

4
Spudly On

I'm not sure I follow the use case, but couldn't you just put an if statement inside the first click and only increment if i does not equal j, or only if i is less than j?

If that works, you can remove the .off()