Open In App

D3.js selection.selectAll() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The selection.selectAll() function in d3.js is used to select all the descendant elements that match the particular selector string which is given as the parameter. If no matches are found then null is returned by this function.

Syntax:

selection.selectAll(selector);

Parameters: The above-given function takes only one parameter which is given above and described below:

  • Selector: This is the name of the container to be selected.

Return Values: It returns the array of elements is found else null is returned..

Below given are a few examples of the function given above.

Example1: When selection is not Null.




<!DOCTYPE html> 
<html lang="en"
<head
    <meta charset="UTF-8"
    <meta name="viewport"
            path1tent="width=device-width, 
                    initial-scale=1.0"> 
    <title>Document</title
</head
<style>
</style
<body>  
    <div>Geeks for geeks
        <b>This text is in bold</b>
        <b>This text is also in bold</b>
    </div>
    <div><b>Geeks for geeks</b></div>
    <div>Some text</div>
  <script src
  </script>
  <script src=
</script>
  <script>
      let selection=d3.selectAll("div").selectAll("b");
      console.log(selection.nodes());
      console.log(selection.node());
  </script
</body
</html>


Output:

Example 2: When selection is null.




<!DOCTYPE html> 
<html lang="en"
<head
    <meta charset="UTF-8"
    <meta name="viewport"
            path1tent="width=device-width, 
                    initial-scale=1.0"> 
    <title>Document</title
</head
<style>
</style
<body>  
    <div>Geeks for geeks
        <b>This text is in bold</b>
        <b>This text is also in bold</b>
    </div>
    <div><b>Geeks for geeks</b></div>
    <div>Some text</div>
  <script src
  </script>
  <script src=
</script>
  <script>
      let selection=d3.selectAll("div").selectAll("br");
      console.log(selection.nodes());
      console.log(selection.node());
  </script
</body
</html>


Output:



Last Updated : 19 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads