Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove the click event using jquery

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.

like image 916
user384080 Avatar asked Jan 22 '23 18:01

user384080


1 Answers

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/

like image 172
Andy E Avatar answered Feb 24 '23 01:02

Andy E