Alex Rivera | Logout

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

Asked 2008-09-23T13:41:07.607
9

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?

Edit
Report

1 Answer

6

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);
});
answered 2010-09-15T15:09:18.390

Your Answer