javascript - How can I remove an attached jQuery function programatically? -


in $.ready() have declared click function shown below

$(document).ready(function(){     $("#btnclk").click(function(clkevent){         //doing here         clkevent.preventdefault();     });  }); 

i want remove click() $("#btnclk") in javascript function. how can this?

one of problems proposed solutions remove click event handlers registered, may not desired.

a solution separate handler method out common scope shared both participating methods use method reference along .off() resolve this

function btnclickhandler(clkevent){     //doing here     clkevent.preventdefault(); }  $(document).ready(function(){     $("#btnclk").click(btnclickhandler); });  $("#btnclk").off('click', btnclickhandler); 

Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -