javascript - D3 selection based on text, but needing sibling element -


i'm struggling specific need, think. i'm drawing tree structure, using node config:

<g class="node" transform="translate(160.65,400)">    <circle r="10" style="fill: rgb(255,255,255);"></circle>    <text y="18" dy=".35em" text-anchor="middle" style="fill-opacity: 1;">data</text> </g> 

what want select circle based on data text tag.

i've been reading subselectors , filters in d3, i'm new , don't quite it. appreciated!

thanks

you have 2 option select text tag.

  1. select parent node class:

    var texttag = d3.select(".node text").text(); if (texttag == "data") {     var circletag = d3.select(".node circle");     console.log(circletag); } else {     console.log("not find"); } 
  2. select tag:

     var texttag = d3.select("text").text();  if (texttag == "data") {     var circletag = d3.select("circle");     console.log(circletag); } else {     console.log("not find"); } 

    complete jsfiddle here.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -