Accepted answer

It seems like you want to add an image element to your div selection using d3js. You don't need to append an svg in order to do this, you can directly append your img element to your div:

const domElement ="#question");
const imagePath = '';
domElement.append('img').attr('src', imagePath);
<script src=""></script>
<div id="question"></div>


Instead of:

.attr('href', 'file://C:/Users/Bryant/Documents/GitHub/ACT/static/js/images/testimage.png')

use this (xlink:href attribute in place of href) :

.attr("xlink:href", function() {return "file://C:/Users/Bryant/Documents/GitHub/ACT/static/js/images/testimage.png"})
.attr('width', "50")
.attr('height', "50")

Related Query

More Query from same tag