Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I want to attach a click event to a button element and then later remove it, but I can't get unclick() or unbind() event(s) to work as expected. In the code below, the button is tan colour and the click event works.

window.onload = init; 
function init() {
    $("#startButton").css('background-color', 'beige').click(process_click);
    $("#startButton").css('background-color', 'tan').unclick();
}

How can I remove events from my elements?

like image 501
Edward Tanguay Avatar asked Sep 23 '08 13:09

Edward Tanguay


1 Answers

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");
like image 167
Jim Avatar answered Sep 26 '22 00:09

Jim