Selecting and modifying DOM elements

D3.js provides a variety of functions to manipulate elements of the DOM tree, such as setting their attributes, changing their content, creating new elements, or removing them. As you learned in the first chapter, instead of looping through elements and modifying them one by one, with D3.js, we are applying transformations in a declarative way directly to an array of elements. We call the object that stores all the elements in an array a Selection.

To extract such an array of elements from the DOM tree, D3.js offers the d3.selectAll(selector) function to select all elements of a specific type and the d3.select(selector) function to select just a single element. While both functions return a Selection that contains ...

Get Data Visualization with D3 and AngularJS now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.