如何在d3.js中选择当前元素的父元素 [英] How to select parent element of current element in d3.js
本文介绍了如何在d3.js中选择当前元素的父元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要访问当前元素的父元素
以下是HTML的结构
svg
g id = invisibleG
g
circle
g
circle
g
circle
基本上,当我将鼠标悬停在圈子中时,我想在圈子中添加文本。
所以我想在任何特定的圆圈上悬停这样的东西
svg
g id = invisibleG
g
circle - >半径增加,文本内部显示
文本
g
circle
g
circle
在悬停时,我可以通过d3.select(this)选择当前元素,我如何获取根元素(在我的情况下是g)?
您可以使用
d3.select(this.parentNode)
选择当前元素的父元素。对于选择根元素,您可以使用d3.select(#invisibleG)
。I want to access the parent element of current element
Here is the structure of HTML
svg g id=invisibleG g circle g circle g circle
Basically I want to add text inside the circles when I hover over them.
So I want something like this on hover of any particular circle
svg g id=invisibleG g circle --> radius is increased and text presented inside that text g circle g circle
On hover I can select current element through d3.select(this),How can I get root element(g in my case)?
解决方案You can use
d3.select(this.parentNode)
to select parent element of current element. And for selecting root element you can used3.select("#invisibleG")
.这篇关于如何在d3.js中选择当前元素的父元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文