Event handling jQuery unclick() and unbind() events?

心已入冬 提交于 2019-12-05 03:32:41

There's no such thing as unclick(). Where did you get that from?

You can remove individual event handlers from an element by calling unbind:

$("#startButton").unbind("click", process_click);

If you want to remove all handlers, or you used an anonymous function as a handler, you can omit the second argument to unbind():

$("#startButton").unbind("click");
alessioalex

Or you could have a situation where you want to unbind the click function just after you use it, like I had to:

$('#selector').click(function(event){
    alert(1);
    $(this).unbind(event);
});
redsquare

unbind is your friend.

$("#startButton").unbind('click')

Are you sure you want to unbind it? What if later on you want to bind it again, and again, and again? I don't like dynamic event-handling bind/unbind, since they tend to get out of hand, when called from different points of your code.

You may want to consider alternate options:

  • change the button "disabled" property
  • implement your logic inside "process_click" function

Just my 2 cents, not an universal solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!