The method .text()
adds text in the selected element. For example:
d3.select('h1').text('This text has been added with D3.js');
The previous example add text in the first <h1>
tag. If the tag already has
a text, the text is replaced.
The method .style()
add or update the CSS style of the selected element. For example:
d3.select('h1').style('color', 'red');
The previous line changes the color of the first <h1>
tag to red.
The method .attr()
add or update the attribute of the selected element. For example:
d3.select('h1').attr('class', 'myClass');
The previous line add myClass
to the first <h1>
tag.
The method .append()
and .insert()
respectively appends and insert a new
element to the selected tag. For example:
d3.select('body').append('h1');
The previous example appends a <h1>
tag to HTML content.
The following example shows some of the methods presented on this page: