Search code examples
jquerylivesettimeout

setTimeOut with JQuery function .live()


I have this:

function toggle() {
    $('#clbttn').fadeOut('fast');
    $('#msg').fadeOut('fast');
    setTimeout(function() { $('#msg').remove(); $('#clbttn').remove(); }, 200);
}
$('#clbttn').live('click', toggle());

And as a result I have this: Uncaught TypeError: Object #clbttn has no method 'apply'

Does anybody know what I should do?


Solution

  • you should change toggle() to toggle, since the former is a function call.

    $('#clbttn').live('click', toggle);