Daft
Daft

Reputation: 10964

Add a link to another page with d3.js

This is probably really straight forward. I'm looking to add a link to another page. I'm trying to add it through d3. Do I add another attribute in the JS? Iv tried .attr("src", "newPage.html") and .attr("url", "newPage.html") but neither work.

Any advice would be appreciated. Thanks.

   //JS
   var newLink = d3.select(".chart")
      .append("div")
      .html("Trend Graph")
      .attr("class", "populationTrend")


    //CSS
   .populationTrend{
       font-weight:400;
       margin-top:-15%;
       cursor:pointer;
       padding-left:70%;
       background-color:#039;
    }   

Upvotes: 1

Views: 8209

Answers (1)

Lars Kotthoff
Lars Kotthoff

Reputation: 109252

To add a "normal" link (i.e. anchor tag), you can simply do

d3.select(".chart")
  .append("a")
  .attr("href", "newPage.html")
  .html("new page");

or even

d3.select(".chart")
  .append("div")
  .html("<a href='newPage.html'>new page</a>");

Upvotes: 9

Related Questions