سؤال

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?

هل كانت مفيدة؟

المحلول

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"});
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top