unbind

first unbind click and then bind (jquery)

微笑、不失礼 提交于 2019-11-27 13:36:59
问题 1.I have a onclick event on, $('#locations').click(function(){ $('#train').unbind('click'); //do some stuff } 2.Once the close button is clicked $('.close').click(function(){ //do some stuff } 3.Then again if I click #train $('#train').bind('click', function() { alert('train is clicked'); //do some stuff } Now the problem is #train is not firing.Is it to bind the event again on .close function? Please suggest.Thanks in advance. 回答1: Looking at your question, you do not seem to bind back the

how to unbind all event using jquery

删除回忆录丶 提交于 2019-11-27 11:17:04
i can use this code to remove click event, $('p').unbind('click') but , has some method to remove all event ? has a method named unbindAll in jquery ? thanks You can call .unbind() without parameters to do this: $('p').unbind(); From the docs : In the simplest case, with no arguments, .unbind() removes all handlers attached to the elements. As of jQuery 1.7, off() and on() are the preferred methods to bind and unbind event handlers. So to remove all handlers from an element, use this: $('p').off(); or for specific handlers: $('p').off('click hover'); And to add or bind event handlers, you can

How to unbind a specific event handler

眉间皱痕 提交于 2019-11-27 07:11:38
Code: $('#Inputfield').keyup(function(e) { if(e.which == 13) { functionXyz(); } else { functionZyx(); } }); $(document).keyup(function(exit) { if (exit.keyCode == 27) { functionZzy(); } }); Question: How to remove the keyup event handler of keyCode == 27 and keep the other $(document).keyup event handlers intact? You have to use a named function so you can reference that specific handler when calling .unbind() , like this: function keyUpFunc(e) { if (e.keyCode == 27) { functionZzy(); } } $(document).keyup(keyUpFunc); Then later when unbinding: $(document).unbind("keyup", keyUpFunc); Your are

jQuery bind/unbind 'scroll' event on $(window)

徘徊边缘 提交于 2019-11-27 01:27:52
问题 I have this function: function block_scroll(key){ if (key) { $(window).bind("scroll", function(){ $('html, body').animate({scrollTop:0}, 'fast'); }); } else { $(window).unbind(); } } The first part works as it should, but when I later call block_scroll(false) - it's still blocking. Wat do? RE-EDIT So as suggested I tried... $(window).unbind("scroll"); ...with some confusion. At first it didn't work - then it worked. Now I think it failed because I was scrolling the moment block_scroll(false)

How do I “rebind” the click event after unbind('click')?

六月ゝ 毕业季﹏ 提交于 2019-11-26 20:26:11
问题 I have an anchor tag <a class="next">next</a> made into a "button". Sometimes, this tag needs to be hidden if there is nothing new to show. All works fine if I simply hide the button with .hide() and re-display it with .show(). But I wanted to uses .fadeIn() and .fadeOut() instead. The problem I'm having is that if the user clicks on the button during the fadeOut animation, it can cause problems with the logic I have running the show. The solution I found was to unbind the click event from

how to unbind all event using jquery

不打扰是莪最后的温柔 提交于 2019-11-26 17:59:48
问题 i can use this code to remove click event, $('p').unbind('click') but , has some method to remove all event ? has a method named unbindAll in jquery ? thanks 回答1: You can call .unbind() without parameters to do this: $('p').unbind(); From the docs: In the simplest case, with no arguments, .unbind() removes all handlers attached to the elements. 回答2: As of jQuery 1.7, off() and on() are the preferred methods to bind and unbind event handlers. So to remove all handlers from an element, use this

How to bind, unbind and rebind (click) events in JQuery

廉价感情. 提交于 2019-11-26 16:30:55
问题 After asking the same question 2 weeks ago here, I finally found "the" solution. This is why I am answering my own question. ;) HOW TO BIND, UNBIND AND REBIND EVENTS IN JQUERY? 回答1: And THIS is the perfect solution. (At least for me.) $(document).on('click', 'a#button', function(){ $(this).after('<span> hello</span>'); $('span').fadeOut(1000); }); $('a#toggle').toggle( function(){ $(this).text('rebind'); $('a#button').on('click.disabled', false); }, function(){ $(this).text('unbind'); $('a