I just want to know how to enable click in jquery. I disabled click on element using .off()
but don't know how to enable it again.
I tried to use the code here, but didn't work or maybe I put it in a wrong way.
I made a simple app that disables the click when the countdown is 3 and below and enable again when the counter resets.
Hope you help me.
Thanks.
var counter = 10;
setInterval(function(e){
$('.counter').text(counter);
counter --;
if (counter <= 3) {
$('button').off('click');
}
if(counter < 0){
counter = 10;
// enable click here
var myFunc = function(event){
event.stopPropagation();
// execute a bunch of action to preform
}
$('button').on('click', myFunc); //bind myFunc
}
}, 1000);
var clicks = 1;
$('button').click(function(){
$('.clicks').text(clicks++);
});
.clicks{
background-color: #DDD;
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="counter"></div>
<br>
<button>click</button>
<div class="clicks">
</div>