D3.js | d3.select() Function
Last Updated :
17 Jul, 2019
The d3.select() function in D3.js is used to select the first element that matches the specified selector string. If any element is not matched then it returns the empty selection. If multiple elements are matched with the selector then only the first matching element will be selected.
Syntax:
d3.select("element")
Parameters: This function accepts single parameter which holds the element name.
Return Value: This function returns the selected elements.
Below programs illustrate the d3.select() function in D3.js:
Example 1:
<!DOCTYPE html>
<html>
<head>
<title>
D3.js | d3.select() Function
</title>
</head>
<body>
<div>GeeksforGeeks</div>
<script>
var a = d3.select( "div" ).text();
console.log(a);
</script>
</body>
</html>
|
Output:
GeeksforGeeks
Example 2:
<!DOCTYPE html>
<html>
<head>
<title>
D3.js | d3.select() Function
</title>
</head>
<body>
<p>GeeksforGeeks</p>
<p>A computer science portal for geeks</p>
<script>
var a = d3.select( "p" ).text();
console.log(a);
</script>
</body>
</html>
|
Output:
GeeksforGeeks
Reference: https://devdocs.io/d3~5/d3-selection#select
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...