jQuery lose focus event
Use blur event to call your function when element loses focus : $(‘#filter’).blur(function() { $(‘#options’).hide(); });
Use blur event to call your function when element loses focus : $(‘#filter’).blur(function() { $(‘#options’).hide(); });
Working DEMO This is a classic JavaScript closure problem. Reference to the i object is being stored in the click handler closure, rather than the actual value of i. Every single click handler will refer to the same object because there’s only one counter object which holds 6 so you get six on each click. … Read more
Combine the focus event with the change event to achieve what you want: (function () { var previous; $(“select”).on(‘focus’, function () { // Store the current value on focus and on change previous = this.value; }).change(function() { // Do something with the previous value after the change alert(previous); // Make sure the previous value is … Read more
You can wire up your own custom event $(‘textarea’).bind(“enterKey”,function(e){ //do stuff here }); $(‘textarea’).keyup(function(e){ if(e.keyCode == 13) { $(this).trigger(“enterKey”); } }); http://jsfiddle.net/x7HVQ/
If the src is already set, then the event is firing in the cached case, before you even get the event handler bound. To fix this, you can loop through checking and triggering the event based off .complete, like this: $(“img”).one(“load”, function() { // do stuff }).each(function() { if(this.complete) { $(this).load(); // For jQuery < … Read more
You can use setTimeout() and clearTimeout() function resizedw(){ // Haven’t resized in 100ms! } var doit; window.onresize = function(){ clearTimeout(doit); doit = setTimeout(resizedw, 100); }; Code example on jsfiddle.
To make sure a click only actions once use this: $(“.bet”).unbind().click(function() { //Stuff });
In modern versions of jQuery, you would use the $._data method to find any events attached by jQuery to the element in question. Note, this is an internal-use only method: // Bind up a couple of event handlers $(“#foo”).on({ click: function(){ alert(“Hello”) }, mouseout: function(){ alert(“World”) } }); // Lookup events for this particular Element … Read more
You just need to keep a reference counter, increment it when you get a dragenter, decrement when you get a dragleave. When the counter is at 0 – remove the class. var counter = 0; $(‘#drop’).bind({ dragenter: function(ev) { ev.preventDefault(); // needed for IE counter++; $(this).addClass(‘red’); }, dragleave: function() { counter–; if (counter === 0) … Read more
An UpdatePanel completely replaces the contents of the update panel on an update. This means that those events you subscribed to are no longer subscribed because there are new elements in that update panel. What I’ve done to work around this is re-subscribe to the events I need after every update. I use $(document).ready() for … Read more