D3 Selections

Learn how the D3 select() and selectAll() methods work on DOM elements.

We'll cover the following

Selection is a fundamental concept used in D3.js. It is used to select DOM elements and manipulate them. In D3.js, we have the following two methods for selection:

  • select() method
  • selectAll() method

select() method

Let’s learn about select(), one of the methods used for selection. It is very powerful, as we will see in the upcoming lessons. It is used to select different HTML tags and manipulate them. If the specified tag is not present, then it will return an empty selection. If multiple instances of the selected tag are present, then it will select the first element only.

Let’s run the famous “hello world” program for D3.js using the select() method.

Get hands-on with 1200+ tech skills courses.