'get event source that triggers events on other elements

In a ASPX MVC view, I use TypeScript to control the client interaction. Some elements' change event could trigger a sequence of other elements' change events. In each of the other element's change() I need to check if it is triggered by the element itself, or preceding element, or by the very first element that fires the event chain. In this example, it is Q12 or Q23, or both. Thanks.

const Q12: any = $('.persistable[id^=Q12_]');
const Q23: any = $('.persistable[id^=Q23_]');
const otherPersistables: any = $('.persistable:not([id^=Q12_]):not([id^=Q23_])');

if (commonUtility.isEmpty(Q12) || commonUtility.isEmpty(Q23)) {
  otherPersistables.each(
    function() {
      //disable this element and trigger it change() event
      $(this).prop('disabled', ture).change();
    }
  );
} else {
  otherPersistables.each(
    function() {
      //enable this element and trigger its change() event
      $(this).prop('disabled', false).change();
    }
  );
}

//add event listener to each of the other persistable elements
otherPersistables.each(
  const thisOtherElment = $(this); 
  thisOtherElment.on("change",
    function() {
     //how to check what really initiates this change if not by this element
     //for example, it could be Q23 or Q12, or both
    }
  }
);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source