Skip to content

Instantly share code, notes, and snippets.

@aumouvantsillage
Created May 13, 2012 17:46
Show Gist options
  • Save aumouvantsillage/2689461 to your computer and use it in GitHub Desktop.
Save aumouvantsillage/2689461 to your computer and use it in GitHub Desktop.
Click events on SVG elements referenced through <use>
Display the source blob
Display the rendered blob
Raw
<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>
@aumouvantsillage
Copy link
Author

This example shows a yellow rectangle and a clone created with a "use" element.
An event handler is registered for the original rectangle.

  • In Chrome and Opera, both rectangles react to click events.
  • In Firefox, the event handler is called only for the original rectangle.

@aumouvantsillage
Copy link
Author

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.

@catalin-enache
Copy link

I can confirm this issue.

@rwieruch
Copy link

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