I am trying to show/hide text of a node in D3 on click. I tried using the following code:
var node = svg.selectAll(".node")
.data(json.nodes)
(...)
node.on("click", function() {
if (textShowing) {
node.select("text").style("visibility", "hidden");
} else {
node.select("text").style("visibility", "visible");
}
textShowing = !textShowing;
});
The code results in text property of all nodes showing/disappearing on click of any of those.
How can I affect the text property of only the clicked node?