You can do this by running
var text = d3.select(this).text();
题
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.