当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - D3: load hyperlink dynamically on click

问题描述:

I'm new to D3 and javascript. I have found a tree layout that suits my needs and now I'm trying to make it display information dynamically. This is the jsfiddle for the tree.

Right now, when you click on a node, a hyperlink is displayed on top of the tree. The problem is that this is just a text string and not a clickable hyperlink.

I know that this is related to my code not actually telling D3 to display this as a hyperlink:

function click(d) {

d3.select("#link").text(d.url);

update(d);

}

I've tried to make it work using the javascript link() method, but wasn't very successful (the debugger said: link() method not found). How can I turn the text string into a clickable link?

网友答案:

Add a <a> tag to the <div> displaying your link:

<div>
  <a id="#link"></a>
</div>

Then, you can update the link tag, like this:

d3.select("#link")
  .attr("href", d.url)
  .text(d.url);
分享给朋友:
您可能感兴趣的文章:
随机阅读: