W3C home > Mailing lists > Public > www-svg@w3.org > May 2010

<use> target/currentTarget handling

From: Nikolas Zimmermann <zimmermann@physik.rwth-aachen.de>
Date: Wed, 05 May 2010 14:06:43 +0200
Message-id: <9B4B3BBA-9DEC-4A56-9788-FC5E8A69CCB8@physik.rwth-aachen.de>
To: www-svg@w3.org
Good morning svg crowd,

I've looked again at WebKit's SVGUseElement/SVGElementInstance  
implementation and came across a problem.
The spec is very vague about the differences between target/ 

Please check the testcase below and its discussion.
Would be _great_ to get some feedback, especially it would be nice to  
get Opera/FF/IE9/WebKit on the same track.


<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink 
        <rect id="rect" fill="red" width="100" height="100"  

    <use id="use" xlink:href="#rect"/>
    <text x="100" y="150" font-size="50" onclick="runTest()">Click me! 

        var rect = document.getElementById("rect");
        var use = document.getElementById("use");
        var rectInstance = use.instanceRoot;

        function eventHandler(evt)
            alert('target: ' + evt.target + ' current target: ' +  

        function fireSimulatedMouseClickEvent(eventTarget)
            var event = document.createEvent("MouseEvents");
            event.initMouseEvent("click", true, true,  
document.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0,  


        function runTest()

How to test

#1) Click on the red rectangle. Should result in:
alert: "target: [object SVGElementInstance] current target: [object  

#2) Click on the text. _I THINK_ it should result in: (that's the path  
I've chosen for WebKit)
alert: "target: [object SVGRectElement] current target: [object  
alert: "target: [object SVGElementInstance] current target: [object  


#1) The first one is logical, the spec says:
If event attributes are assigned to referenced elements, then the  
actual target for the event will be the SVGElementInstance object  
within the "instance tree" corresponding to the given referenced  

#2) This is tricky.  think it should be possible to dispatch an event  
manually to every element in the DOM.
So dispatching directly to "rect", should work as expected, and not  
end up on a SVGElementInstance. This should explain the expected  
result for the first alert(), as stated above. Is it correct?

When dispatching manually to the "rectInstance" WebKit delivers it to  
the SVGElementInstance, and Opera does not. It says "target: [object  
SVGRectElement] current target: [object SVGRectElement]"
Can anyone explain what's happening? Just a bug in Opera? I think the  
spec clearly states here, that the event should end up on the  

Further questions

Spec says: The event handling for the non-exposed tree works as if the  
referenced element had been textually included as a deeply cloned  
child of the 'use' element, except that events are dispatched to the  
SVGElementInstance objects. The event's target and currentTarget  
attributes are set to the SVGElementInstance that corresponds to the  
target and current target elements in the referenced subtree
The currentTarget attribute of the event can be used to determine  
through which object an event listener was invoked.

What does the last sentence mean in practice? Does it talk about  
target pointing to eg. SVGRectElement, but currentTarget pointing to a  
Of course when the event bubbles currentTarget and target are not  
equal anymore, but I'm wondering about the target phase. The sentence  
above makes me thing there is some difference that I'm overlooking.
To rephrase: When is currentTarget != target? Only when capturing/ 

Can anyone enlighten me?

Thanks in advance,
Received on Wednesday, 5 May 2010 12:07:18 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 8 March 2017 09:47:21 UTC