tags:

views:

364

answers:

1

When attaching a function to the onmouseover event for an SVG group <g>...</g>, the event occurs once, each time the pointer enters to an element in the group.

This occurs even if two elements in the group appears one inside another.

For example:

+-----+
|A ___|
|  |B |
|__|__|

When the pointer enters the A rectangle, and from there moves to the B rectangle without leaving A, the onmouseover events is triggered for the group G which contains both A and B.

The event occurs only once, so I don't think it relates to events bubbling.

I expected the group to to be treated as a solid block, so that I won't have to worry about its descendants when setting its own events.

Any work-around? Am I doing that correctly? Is there a better way?

+1  A: 

Sounds familiar, I think the bubbling will bite you in such cases.

Some examples from one of my SVG Open presentations in 2008, in particular slide 17 should be of interest. It might be that having something like 'mouseenter'/'mouseleave' events would solve this, but they're not yet in a w3c recommendation.

Erik Dahlström
Thanks! Great to see more folks ran into the same problem. But I don't get it. Shouldn't event bubbling cause two events to be triggered? One from the inner rectangle, and the other from the outer rectangle?
Elazar Leibovich
An example would be nice, maybe I'm misunderstanding your problem.
Erik Dahlström
Let us look at rectangles A and B as above. When the mouse is already in rectangle B, and now we're moving it to rectangle A only. In this case I expect rectangle A not to get a mouseover event, as the pointer was already above it. However it does get the mouseover event. likewise when I'm entering rectangle B from outside, I expect to get two mouseover events, one from rectangle A and one from rectangle B.
Elazar Leibovich
Bubbling operates on the DOM level, and you can't have a rect be a child of another rect. They're siblings, and only one of the rects can be the target of the mouseover event. The event will be targetted to the element that is topmost in rendering order. The events then bubble up to the 'g' element containing the rects.
Erik Dahlström