It would be very helpful if someone could help me figure out why I cannot programmatically fire events when using event delegation in MooTools (from the Element.Delegation class).
There is a parent <div> that has a change listener for some child <input> elements. When a change event is triggered by user actions, the handler in the parent div fires, but when I fire it programmatically using fireEvent on any child input, nothing happens. Basic setting:
HTML
<div id="listener"> <input type="text" id="color" class="color" /> ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ</div>βββββββββββ
Js
$("listener").addEvent("change:relay(.color)", function() { alert("changed!!"); }); $("color").fireEvent("change");
The event handler in the parent div is not called. Any help is appreciated. Hooray!
Related question: do events triggered with a fireEvent bubble generally fireEvent in the DOM tree? My current hack is to send the event initially, but it works (but the hack, nonetheless) - http://jsfiddle.net/SZZ3Z/1/
var event = document.createEvent("HTMLEvents") event.initEvent("change", true); document.getElementById("color").dispatchEvent(event);
javascript mootools javascript-events event-delegation
Anurag
source share