Skip to content

Instantly share code, notes, and snippets.

@AmeliaBR
Forked from anonymous/index.html
Created July 10, 2016 00:58
Show Gist options
  • Save AmeliaBR/799b95f685dc58e7eb51ee035174f88c to your computer and use it in GitHub Desktop.
Save AmeliaBR/799b95f685dc58e7eb51ee035174f88c to your computer and use it in GitHub Desktop.
SVG shadow tree event listener test // source http://jsbin.com/dubazuzoke
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>SVG shadow tree event listener test</title>
</head>
<body>
<svg>
<circle id="c" cx="50" cy="50" r="40" />
<use fill="red" x="100" xlink:href="#c" />
</svg>
<script id="jsbin-javascript">
function makeClickHandler(name) {
return function clickHandler(event){
console.log(
[name,
'target =',
event.target.constructor.name,
'target.parentNode =',
(event.target.parentNode? event.target.parentNode.constructor.name : 'null'),
'; currentTarget =',
event.currentTarget.constructor.name
].join(' '));
};
}
document.querySelector("svg").addEventListener("click", makeClickHandler("SVG handler:"));
document.querySelector("circle").addEventListener("click", makeClickHandler("Circle handler:"));
document.querySelector("use").addEventListener("click", makeClickHandler("Use handler:"));
</script>
<script id="jsbin-source-javascript" type="text/javascript">function makeClickHandler(name) {
return function clickHandler(event){
console.log(
[name,
'target =',
event.target.constructor.name,
'target.parentNode =',
(event.target.parentNode? event.target.parentNode.constructor.name : 'null'),
'; currentTarget =',
event.currentTarget.constructor.name
].join(' '));
};
}
document.querySelector("svg").addEventListener("click", makeClickHandler("SVG handler:"));
document.querySelector("circle").addEventListener("click", makeClickHandler("Circle handler:"));
document.querySelector("use").addEventListener("click", makeClickHandler("Use handler:"));</script></body>
</html>
function makeClickHandler(name) {
return function clickHandler(event){
console.log(
[name,
'target =',
event.target.constructor.name,
'target.parentNode =',
(event.target.parentNode? event.target.parentNode.constructor.name : 'null'),
'; currentTarget =',
event.currentTarget.constructor.name
].join(' '));
};
}
document.querySelector("svg").addEventListener("click", makeClickHandler("SVG handler:"));
document.querySelector("circle").addEventListener("click", makeClickHandler("Circle handler:"));
document.querySelector("use").addEventListener("click", makeClickHandler("Use handler:"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment