admin管理员组文章数量:1296301
I understand event can be removed from an element by using .unbind() or .off(). However I am wondering if is that possible to remove specific click event and leave others attached. For example assuming I have a element with two events attached as follow:
$("#MyDiv").click(function() {
alert("I am first Event");
});
$("#MyDiv").click(function () {
alert("I am second Event");
});
Is that possible to remove First event and leave second one attached, using some sort of key?
I understand event can be removed from an element by using .unbind() or .off(). However I am wondering if is that possible to remove specific click event and leave others attached. For example assuming I have a element with two events attached as follow:
$("#MyDiv").click(function() {
alert("I am first Event");
});
$("#MyDiv").click(function () {
alert("I am second Event");
});
Is that possible to remove First event and leave second one attached, using some sort of key?
Share Improve this question asked Jan 27, 2015 at 9:27 cyrus-dcyrus-d 8431 gold badge14 silver badges36 bronze badges1 Answer
Reset to default 13You can use event name spacing and .off()
$("#MyDiv").on('click.first', function () {
alert("I am first Event");
});
$("#MyDiv").on('click.second', function () {
alert("I am second Event");
});
$("#MyDiv").off('click.first');
Demo: Fiddle
本文标签: javascriptRemove specific jQuery click event from elementStack Overflow
版权声明:本文标题:javascript - Remove specific jQuery click event from element - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741635365a2389610.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论