I am trying to toggle a click event on and off to prevent multiple function calls. Below is my code. The click is turning off but I can't seem to turn it on again. Thoughts?
$("#element").click(function(){
     doit();
     $(this).off('click');
 })
function doit(){
    do stuff...
    //turn click back on
    $("#element").on('click');
}
                You need to pass the handler back to the on method, also use .one() as you want to fire it only once
function clickHandler() {
    doit();
}
$("#element").one('click', function () {})
function doit() {
    //do stuff...
    //turn click back on
    $("#element").one('click', clickHandler);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With