Add a circle at mouse's location. Remove the previous circle to just keep the current one.
xxxxxxxxxx
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
svg {
background-color: #4d4d4d;
width: 500px;
height: 500px;
}
circle {
fill: #b2182b;
}
</style>
</head>
<body>
<svg></svg>
</body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script type="text/javascript">
function mousemove() {
d3.select("circle").remove() // Remove the previous circle. Only diffrence from block "Add circle at mouse's location (1/2)"
var coords = d3.mouse(this);
d3.select("svg").append("circle")
.attr("cx", coords[0])
.attr("cy", coords[1])
.attr("r", 10)
}
var svg = d3.select("svg")
svg.on("mousemove", mousemove)
</script>
</html>
https://d3js.org/d3.v4.min.js