Note that there are some explanatory texts on larger screens.

plurals
  1. POMooTools - Programmatically fired events not working with event delegation
    primarykey
    data
    text
    <p>Would really appreciate if anyone can help me figure out why I am unable to fire events programmatically when using event delegation in MooTools (from the Element.Delegation class).</p> <p>There is a parent <code>&lt;div&gt;</code> that has a <code>change</code> listener on some child <code>&lt;input&gt;</code> elements. When the change event is triggered by user actions, the handler on the parent div gets triggered, but when I fire it programmatically with <code>fireEvent</code> on any child input, nothing happens. The basic setup is:</p> <h3>html</h3> <pre><code>&lt;div id="listener"&gt; &lt;input type="text" id="color" class="color" /&gt; ​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​&lt;/div&gt;​​​​​​​​​​​ </code></pre> <h3>js</h3> <pre><code>$("listener").addEvent("change:relay(.color)", function() { alert("changed!!"); }); $("color").fireEvent("change"); // nothing happens </code></pre> <p>The event handler on the parent div does not get called. Any help is appreciated. Cheers!</p> <hr /> <p>Related question: Do events triggered with <code>fireEvent</code> bubble at all in the DOM tree? My current hack is to dispatch the event natively which is working (but a hack nonetheless) - <a href="http://jsfiddle.net/SZZ3Z/1/" rel="noreferrer">http://jsfiddle.net/SZZ3Z/1/</a></p> <pre><code>var event = document.createEvent("HTMLEvents") event.initEvent("change", true); document.getElementById("color").dispatchEvent(event); // instead of fireEvent </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload