I have an SVG text element:

<text class="countries" dy="0" dx="-339.87646027037385" font-size="22" style="fill:      #1f77b4;">Afghanistan</text>

and all I want to do is to grab the "Afghanistan" text from that on a click event. d3.select(this)...

Thanks!

有帮助吗?

解决方案

You can do this by running

var text = d3.select(this).text();

其他提示

If you want the click event on your svg Element:

When generating your element you can add a click event using:

.on("click", function(){
   // ...
}

Does the text you want come out of your data? Then you could do something like:

.on("click", function(d){
   window.alert(d.text)
}

Hope that helped.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top