Created
May 13, 2012 17:46
-
-
Save aumouvantsillage/2689461 to your computer and use it in GitHub Desktop.
Click events on SVG elements referenced through <use>
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
<svg | |
xmlns="http://www.w3.org/2000/svg" | |
xmlns:xlink="http://www.w3.org/1999/xlink" | |
width="120" height="170"> | |
<rect id="original" | |
x="10" y="10" width="100" height="50" | |
stroke="black" fill="yellow" /> | |
<use id="clone" xlink:href="#original" | |
transform="translate(0, 100)" /> | |
<script> | |
document.getElementById("original") | |
.addEventListener("click", | |
function (evt) { | |
alert("Clicked!"); | |
}, | |
false); | |
</script> | |
</svg> |
From http://www.w3.org/TR/SVG11/struct.html#UseElement :
An event propagates through the exposed and non-exposed portions of the tree in the same manner as it would in the regular document tree: first going from the root element to the ‘use’ element and then through non-exposed tree elements in the capture phase, followed by the target phase at the target of the event, then bubbling back through non-exposed tree to the use element and then back through regular tree to the root element in bubbling phase.
I can confirm this issue.
Has someone found a solution for that?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This example shows a yellow rectangle and a clone created with a "use" element.
An event handler is registered for the original rectangle.