Note that there are some explanatory texts on larger screens.

plurals
  1. POMooTools: How do I make an object capture a custom event occured in its nested object?
    primarykey
    data
    text
    <p>Here's the simplified code:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; var ParentDiv = new Class ({ initialize : function(htmlElement) { console.log('debug: parent object created'); $$('.childDiv').each(function(childDiv){ childDiv = new ChildDiv(childDiv); }) htmlElement.addEvents({ 'click': function (){ console.log('debug: clicked parent'); }, 'testEvent' : function(){ console.log('debug: complex logic altering inner HTML of the element'); } }) } }); function initParent () { $$('.parentDiv').each(function(parentDiv){parentDiv = new ParentDiv(parentDiv);}) } var ChildDiv = new Class ({ initialize : function(htmlElement) { console.log('debug: child object created'); htmlElement.addEvent('click', function (){ console.log('debug: clicked child'); this.addEvent('testEvent', function(){console.log('debug: grabbed an event in child element, fired by child element')}) this.fireEvent('testEvent'); }) } }); document.addEvent('domready', function(){ initParent(); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div class="parentDiv"&gt; &lt;div&gt; &lt;div&gt; &lt;div&gt; &lt;div class="childDiv"&gt;Clicky Thingy&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The outcome is the following: neither of the events are grabbed by parent object's event listeners, while capturing the events is something I'm trying to achieve. A possible occurance of such structure: we have a bunch of control elements on the page, they all fire their own events, while the document or any other kind of container manipulates the content within based on the captured event's type.</p> <p>So, is there a way to make 'debug: complex logic altering inner HTML of the element' appear in the console box with the use of custom events?</p>
    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