Frage

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!

War es hilfreich?

Lösung

You can do this by running

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

Andere Tipps

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top