0

I have the following D3 code which I'd like to add CSS to:

  // Update the links…
  var link = vis.selectAll("path.link")
      .data(tree.links(nodes), function(d) { return d.target.id; });

  // Enter any new links at the parent's previous position.
  link.enter().insert("svg:path", "g")
      .attr("class", "link")
      .attr("d", function(d) {
        var o = {x: source.x0, y: source.y0};
        return diagonal({source: o, target: o});
      })
    .transition()
      .duration(duration)
      .attr("d", diagonal);

  // Transition links to their new position.
  link.transition()
      .duration(duration)
      .attr("d", diagonal);

  link.style("stroke", function(d, i){
    console.log();
    if((i == ((link.size()/2)-1) || i == ((link.size()/2)-2)) && (AMLsIncluded == true)){
        return "white";
    }
  });

I use the following code to change the CSS but nothing happens:

$(".link path").css({"fill":"none", "stroke":"#ccc", "stroke-width":"1.5px"});

Am I grabbing path.link the right way? I used to have my css in a seperate .css file, but I need to make it dynamic for several reason. This works when imported from a CSS file:

path.link {
  fill: none;
  stroke: #ccc;
  stroke-width: 1.5px;
}

What am I doing wrong?

1 Answer 1

1

You need to use the same selector you use in your D3 code and CSS file:

$("path.link").css({"fill":"none", "stroke":"#ccc", "stroke-width":"1.5px"});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.