How do you get an SVG to come to the front in Javascript? The answer is to use D3 moveToFront() or try adding a script to the html like the following:
[<script>
d3.selectAll('circle').on('mouseenter', function() {
this.parentElement.appendChild(this);
});
</script>][2]
However, I try to get the SVG to show it never works. Now I know the SVG element is created because it appears in developer mode on the click event, . It is also the last element on that list. Thank you.
Here's a Fiddle, so you can see what I'm talking about. https://jsfiddle.net/Math8Gr/fzpqdkwg/
This is the code in question:
$('div.cell').click(function() {
//create SVG
var point = document.createElementNS('http://www.w3.org/2000/svg', 'circle');
//set attributes
point.setAttribute('cx', 100);
point.setAttribute('cy', 75);
point.setAttribute('r', 8);
point.setAttribute('fill', 'red');
//Add to parent node
document.getElementById('grid').appendChild(point, function() {
var sel = d3.select(point);
sel.moveToFront();
});