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

jQuery watch for domElement changes?

The most effective way I’ve found is to bind to the DOMSubtreeModified event. It works well with both jQuery’s $.html() and via standard JavaScript’s innerHTML property. $(‘#content’).bind(‘DOMSubtreeModified’, function(e) { if (e.target.innerHTML.length > 0) { // Content change handler } }); http://jsfiddle.net/hnCxK/ When called from jQuery’s $.html(), I found the event fires twice: once to clear … Read more

jQuery event for HTML5 datalist when item is selected or typed input match with item in the list

On modern browsers, you can use input event, e.g: $(“#name”).on(‘input’, function () { var val = this.value; if($(‘#allNames option’).filter(function(){ return this.value.toUpperCase() === val.toUpperCase(); }).length) { //send ajax request alert(this.value); } }); <script src=”https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js”></script> <input id=”name” list=”allNames” /> <datalist id=”allNames”> <option value=”Adnan1″ /> <option value=”Faizan2″ /> </datalist> PS: as input event has better support than datalist … Read more

jQuery .click() is triggering when selecting/highlighting text

That’s because a click is a mousedown followed by a mouseup. My suggestion is to check getSelection inside the click handler. If it’s set, then you selected something, else you just clicked. $(‘#click’).click(function() { var sel = getSelection().toString(); if(!sel){ alert(“clicked”); } });​ DEMO: http://jsfiddle.net/ym5JX/3/

Jquery on hover not functioning

Deprecated as of jQuery 1.8: The name “hover” used as a shorthand for the string “mouseenter mouseleave”. It attaches a single event handler for those two events, and the handler must examine event.type to determine whether the event is mouseenter or mouseleave. Do not confuse the “hover” pseudo-event-name with the .hover() method, which accepts one … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)