📜  D3.js selection.select()函数

📅  最后修改于: 2022-05-13 01:56:30.750000             🧑  作者: Mango

D3.js selection.select()函数

d3.js 中的selection.select()函数用于选择与给定选择器匹配的第一个后代元素。如果未找到该元素,则该函数返回 null。

句法:

selection.select(selector);

参数:上面给出的函数只接受一个上面给出和下面描述的参数:

  • 选择器:这是 HTML 容器或 SVG 标记的名称。

返回值:如果找到则返回一个元素,否则返回null。

下面给出了上面给出的函数的几个例子。

示例 1:

html



    
    
    Document


 
    
Some text
    
Geeks for geeks
    
Geeks for geeksThis is from b tag
    
Some text
        


html



    
    
    Document


 
    
Some text
    
Geeks for geeks
    
Geeks for geeksThis is from b tag
    
Some text
        


输出:

示例 2:当未找到元素时,返回 null。

html




    
    
    Document


 
    
Some text
    
Geeks for geeks
    
Geeks for geeksThis is from b tag
    
Some text
        

输出: