click events on svg:text nodes

1,722 views
Skip to first unread message

Bob Monteverde

unread,
Dec 2, 2011, 2:10:15 PM12/2/11
to d3-js
Ok, this is confusing the hell out of me, and if its not a common
problem, I'll do my best to create minimal examples of whats going on.


I'm trying to bind a click event on the text using the usual:
textNodes.on('click', function(d) { .... });

Now this is whats killing me, I have one example where I'm creating
control buttons that are simply text nodes with click events... this
works as I would hope it would.

On a separate visualization, I have a selection of containers that I
am appending svg:text nodes to, and trying the same technique for
binding click. But in this case, the event won't fire. I'm having a
hard time figuring out whats different between these two text nodes,
as far as the text nodes go, they are both defined in almost the exact
same way, just one is on a selection while the others I am just adding
individuals to where I want them in a group.

I apologize for the horrible job at identifying the exact issue, but
hoping this may be a really common issue people have ran into, and
could maybe give me a generic way of fixing this. If this isn't
common, and everyone has no idea what I'm doing wrong, I'll do my best
to create examples to reproduce my issue.

Thanks,

Bob

Bob Monteverde

unread,
Dec 2, 2011, 2:14:51 PM12/2/11
to d3-js
Hmm, one this I can see that's different is the 'G' node they are in..
the one that isn't working has a translate transform, though still not
sure if that has anything to do with my problem.

Mike Bostock

unread,
Dec 2, 2011, 2:35:24 PM12/2/11
to d3...@googlegroups.com
First check that you're applying the `on` operator to the intended
elements. For example, log the definition of textNodes to the console
before you call `on`, or use the debugger to stop the code and inspect
the elements.

Second check that you haven't disabled pointer-events on text elements
(via CSS), which some of the examples do.

Mike

Bob Monteverde

unread,
Dec 2, 2011, 2:38:44 PM12/2/11
to d3-js
WOW, I am kicking myself in the ass. I'm literally staring at that
exact line of css, and it wasn't registering in my head. Apparently I
desperately need sleep.

Thanks!

Reply all
Reply to author
Forward
0 new messages