【发布时间】:2012-05-15 19:44:40
【问题描述】:
我创建了以下文档:
<g>
<path class="line" name="gene_1" stroke="#aec7e8" d="M10.47..."></path>
<path class="line" name="gene_2" stroke="#aec7e8" d="M10.47..."></path>
<path class="line" name="gene_3" stroke="#aec7e8" d="M10.47..."></path>
...
</g>
当我将鼠标悬停在每条路径上时,我想将其最后附加到 svg:g 中,以便它出现在其他行的顶部,但我不知道如何正确选择 parentNode:
function onmouseover(d, i){
var current_gene_name = d3.select(this).attr("name"),
current_gene_pcp = d3.select(".line[name=" + current_gene_name + "]");
p1 = this.parentNode
p2 = current_gene_pcp[0].parentNode
p3 = current_gene_pcp[0][0].parentNode
//p.appendChild(this);
}
p1 有效,但我想确保this 是.line,所以我更喜欢使用current_gene_pcp,但p2 返回<html></html> 作为父级,即使p3返回正确的<g></g>。最后一个版本似乎是一个等待发生的错误。有没有更好的办法?
【问题讨论】:
标签: javascript d3.js