D3.js offers two simple ways to select HTML elements. The first one is d3.select();
which select the first element. The element to select is defined thanks to CSS style
selectors. Here are some example :
d3.select('h1');
- select the first <h1>
tag from the DOM.d3.select('#myID');
- select the element with ID myId
from the DOM.d3.select('.myClass');
- select the element with class myClass
from the DOM.Here is a small example that select elements from the DOM:
You can also select several elements at one time. This is the role of the
d3.selectAll()
function. This functions works as the previous one, but select
several elements at the smae time:
d3.select('.myClass');
- select all the elements with class myClass
from the DOM.