views:

17

answers:

1

Hi,

I have a jquery code to set the click event as follow: $("#somediv").click(function() {alert('test')});

How do I remove the above click event? it seems that the .click() method will always append the exisiting ones.

+2  A: 

Use

$('#somediv').unbind('click');

If you only want to remove that function, you need a reference to it:

var test = function() {alert('test');};
$("#somediv").click(test);

window.setTimeout(function () {
    $('#somediv').unbind('click', test);
}, 10000);

http://api.jquery.com/unbind/

Andy E
You beat me by 30 seconds.
ok.. another question then.. how to remove the hover? it seems the unbind('hover') does not do the work
hahahahha.. sorry found the answer from http://stackoverflow.com/questions/805133/how-do-i-unbind-hover-in-jquery