d3.select by attribute value

后端 未结 1 511
名媛妹妹
名媛妹妹 2021-01-31 17:46

I am new to d3. I have something defined like this:

node = node.enter().append(\"circle\")
            .attr(\'id\', function(d){ return d.id; })
            .at         


        
1条回答
  •  有刺的猬
    2021-01-31 18:17

    Your problem is that ids and names must begin with a letter. So modify your code to prepend a string to each id, e.g.

    .attr('id', function(d){ return 'name' + d.id; })
    

    Then, you can select a given node by using d3.select( '#name' + i ). From the docs on D3 selections:

    ... you can select by tag ("div"), class (".awesome"), unique identifier ("#foo"), attribute ("[color=red]"), or containment ("parent child").

    0 讨论(0)
提交回复
热议问题