How to get value from the element using selection in d3
d3.js, svg
Solution
You need a child selector here (and call the `.text()` function):
d3.select("g.tooltip > text.name").text();
Problem
I'm using D3 with SVG and having one question regarding selections. I have an element in th DOM like the following: ``` <g class="tooltip"> // some other code <text class="name">Testing D3</text> </g> ``` Now I want to get the text "Testing D3" using selections. How can I do it? I've tried the following: ``` d3.select(".tooltip .name").text d3.select(".tooltip .name").value d3.select(".tooltip .name").textContent d3.select(".tooltip .name").html ``` But none of them is working. I've also tried using ``` d3.select(".tooltip .name").html(this.value); ``` as suggested here and here, but that's giving me an `SVGTextElement` & not the actual value. Also I cannot use `document.getElementById("name");`, as suggested here, because I have to achieve this functionality through d3 only. Please note that name is a single element.