Skip to content

Event.target is SVGElementInstance #9

@mems

Description

@mems

From SVG 1.1 specs event.target refer to the instance in the shadow tree. In SVG 2.0 it refer to the SVGUseElement

  • Edge 12-15: SVG 1.1
  • IE 8-11: SVG 1.1
  • Firefox: SVG 2.0
  • Chrome: SVG 2.0

Polyfill:

// Polyfill for IE10+ and Edge
if (window.SVGElementInstance) {
	// There is a false positive for Firefox where SVGElementInstance exist, but not used for event.target
	var desc = Object.getOwnPropertyDescriptor(Event.prototype, "target");// some browsers (Android stock browser) return null for property descriptor of Event.prototype.target. Use non-standard property Event.prototype.srcElement instead
	Object.defineProperty(Event.prototype, "target", {
		configurable: true,
		get: desc ? function() {
			var target = desc.get.call(this);
			return target && target.correspondingUseElement || target;
		} : function() {
			var target = this.srcElement;
			return target && target.correspondingUseElement || target;
		}
	});
}

Or use event.target.correspondingUseElement instead of just event.target

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions