Cancel click event in the mouseup event handler

Use the event capture phase Put an element around the element you want to cancel the click event for, and add a capture event handler to it. var btnElm = document.querySelector(‘button’); btnElm.addEventListener(‘mouseup’, function(e){ console.log(‘mouseup’); window.addEventListener( ‘click’, captureClick, true // <– This registeres this listener for the capture // phase instead of the bubbling phase! ); … Read more

jQuery .on() method doesn’t see new elements

You are not using the correct code to get live functionality. $(‘#title-items’).on(‘click’, ‘a’, function(e) { alert(‘clicked’); e.preventDefault(); }); First, select your common ancestor element (#title-items in this example). You can use document here too if you want to handle all a elements. Pass the event type (on), then the sub selector (a), and then the … Read more

jQuery Datepicker “After Update” Event or equivalent

if you need a “afterShow”-event before jquery-ui version 1.9 you can overwrite the datepicker._updateDatepicker function. for example: $(function() { $.datepicker._updateDatepicker_original = $.datepicker._updateDatepicker; $.datepicker._updateDatepicker = function(inst) { $.datepicker._updateDatepicker_original(inst); var afterShow = this._get(inst, ‘afterShow’); if (afterShow) afterShow.apply((inst.input ? inst.input[0] : null)); // trigger custom callback } }); Now the datepicker raise an “afterShow” event after every update … Read more

triggerHandler vs. trigger in jQuery

From the Docs at http://api.jquery.com/triggerHandler/ The .triggerHandler() method behaves similarly to .trigger(), with the following exceptions: The .triggerHandler() method does not cause the default behavior of an event to occur (such as a form submission). Not preventing the default browser actions allow you to specify an action that occurs on focus or select, etc etc … Read more