matchingTarget 属性

Element matchingTarget

指向触发事件的元素,该元素的 CSS 选择器匹配了事件发生的位置。如果此事件未与任何事件委托关联,访问此值将抛出 UnsupportedError

实现

Element get matchingTarget {
  if (_selector == null) {
    throw new UnsupportedError('Cannot call matchingTarget if this Event did'
        ' not arise as a result of event delegation.');
  }
  Element? currentTarget = this.currentTarget as Element?;
  Element? target = this.target as Element?;
  var matchedTarget;
  do {
    if (target!.matches(_selector!)) return target;
    target = target.parent;
  } while (target != null && target != currentTarget!.parent);
  throw new StateError('No selector matched for populating matchedTarget.');
}