-
-
Save AmeliaBR/799b95f685dc58e7eb51ee035174f88c to your computer and use it in GitHub Desktop.
SVG shadow tree event listener test // source http://jsbin.com/dubazuzoke
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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