1

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;
    }   
Daft
  • 10,277
  • 15
  • 63
  • 105

1 Answers1

9

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>");
Lars Kotthoff
  • 107,425
  • 16
  • 204
  • 204