Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8556009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:15:07+00:00 2026-06-11T15:15:07+00:00

How can the parent fire the custom event to notify its children/siblings? For example:

  • 0

How can the parent fire the custom event to notify its children/siblings?
For example:

<div id="div1">
   <div id="div2"></div>
</div>

div2 had addEventListener('customEvent2', doSth), and then div1 will fire a custom event (customEvnet2), but this will never trigger div2’s doSth function.

Sample code: http://jsfiddle.net/r4tcT/2/

The "div 1 trigger customEvent 2" button never works

so when a parent fire a custom event (dispatchEvent[IE9]/fireEvent[IE9-]/trigger[jQuery]), the children can not capture the event.

Is there any workaround?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:15:07+00:00Added an answer on June 11, 2026 at 3:15 pm

    The difference you are talking about is either between the ‘Capturing’ event model or the ‘Bubbling’ event model. jQuery’s trigger operates on the Bubble model probably because this is the more supported event model — mainly thanks to Internet Explorer. The Bubble model only travels backwards up through an elements parents… this is the reason why your events don’t trigger on div2 when fired from div1, as it is always bubbling up and not down.

    I’ve not tried custom events before with native functions but most modern browsers allow for you to decide which type of model you use when you set the event listener:

    addEventListener (type, listener[, useCapture])
    

    https://developer.mozilla.org/en-US/docs/DOM/element.addEventListener

    Basically if you use true as the final argument the event listener should trigger in the Capture phase (which is when the event is travelling down the dom tree). If set to false the event will trigger in the bubbling phase which occurs when travelling back up the dom tree.

    This has been discussed here:

    Event Capturing vs Event Bubbling

    As I’ve said whether this will work for bespoke events I’m not sure. I am pretty certain you can not do this with jQuery (as of yet) probably due to the lack of support in older browsers.

    Correction

    It appears what I guessed at above doesn’t work. I thought as much due to the term ‘Capturing’ kind of makes you think about capturing user input — and when bespoke events are involved there is no way to define a new kind of user input. So with that in mind I put together this quick jQuery plugin… it’s only been roughly tested, but the logic should be sound – hope it’s useful:

    /**
     * unbubble v0.2
     *
     * trigger an event down through the children of a collection, 
     * rather than up through it's parents
     *
     *  @update 2013/03/18 - fixed the problem of triggering bubble phase each
     *    step down the element tree as pointed out by @vine.
     */
    $.fn.unbubble = function( eventNames ){
      var names = eventNames.split(' '), 
          non = names.length, 
          args = Array.prototype.slice.call(arguments);
      /// our own trigger function designed to bubble down... not up!
      var trigger = function(){
        var i, events, elm = $(this);
        /// make sure we can read the events array
        if ( $._data ) {
          /// make sure events is defined
          if ( (events = $._data(this, 'events')) ) {
            /// do a quick check, saves firing trigger on every element found
            for ( i=0; i<non; i++ ) {
              /// make sure our eventName appears in the event list
              if ( names[i] && ( names[i] in events ) ) {
                /// trigger the standard jQuery trigger function
                elm.triggerHandler.apply(elm, args);
                /// escape as trigger should fire for multiple names
                break;
              }
            }
          }
        }
        /// if we can't access the events array, just trigger and hope
        else {
          /// trigger the standard jQuery trigger function
          elm.triggerHandler.apply(elm, args);
        }
        /// trigger for all the children, and on, and on...
        elm.children().each(trigger);
      };
      /// foreach element trigger now...
      this.each(trigger);
    }
    
    /**
     * Example usage
     */
    $(function(){
      /// bind our event as usual
      $('.div2').bind('customEvent', function(){
        alert('I should trigger!');
      });
      /// rather than use trigger, fire with unbubble
      $('#div1').unbubble( 'customEvent' );
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I stop parent binds to be called? Example: <div id=test> <a href=#
Summary A parent can have many children. How do you write a service such
Using parent child relationship where a parent can have children while each child has
I have a simple parent-child situation where the parent can have multiple children. The
Is there a way how modules can listen to parent application event? My current
Sample data: I can flatten out parent-child relationship using this query.... Any help... Thanks
I know I can have 1 parent element and 1 child element in my
I am trying to access child class variables in parent class..can u suggest me
how can i get immediate parent of a given element ? $(e.target).parent() ?
Can I automatically validate complex child objects when validating a parent object and include

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.