Pergunta

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!

Foi útil?

Solução

You can do this by running

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

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top