[D3] Modify DOM Elements with D3 v4

Once you can get hold of DOM elements you’re ready to start changing them. Whether it’s changing colors, labels, or even link destinations, this lesson demonstrates the process and patterns for updating the DOM using D3’s powerful APIs.

 

// you will see two red links when viewing this on Plunker
// we did not see this behavior in the lesson video
// because our BrowserSync dev server was inserting a script
// making the last link NOT a second child

d3.selectAll('a:nth-child(2)')
  .attr('href', 'http://google.com')
  .classed('red', true)
  .html('Inventory <b>SALE</b>');

 

posted @ 2017-08-02 02:17  Zhentiw  阅读(216)  评论(0编辑  收藏  举报