I start with svg and I created the following markup.
<svg width="500" height="600" class="graph-container">
<g>
<rect x="150" y="190" height="50" width="200" rx="30" ry="30" nodeId="1" children="3" style="fill: none; stroke: rgb(68, 68, 68);"></rect>
<text x="250" y="220" text-anchor="middle" fill="#444" style="font-size: 24px;">root</text>
</g>
</svg>
I added a small circle to the big rectangle through d3js.
$( document ).ready(function() {
var node = d3.select('g');
var addchild = node.append("circle")
.attr("cx",320)
.attr("cy",210)
.attr("r",10)
.attr("class","addchild")
.style("fill","none")
.style("stroke","#444");
addchild.on("click", function() {
alert("on click");
});;
});
but the click event does not fire.
Here is the jsfiddle of the same.
source
share