I’m trying to add an image to an SVG file..
I tried this code::
drawImage : function(src, x, y, h, w) {
var img = document.createElementNS("http://www.w3.org/2000/svg", "image");
var $img = $(img);
$img.attr('x', x);
$img.attr('y', y);
$img.attr('width', w);
$img.attr('height', h);
$img.attr('xlink:href', src);
$('g').append($img);
}
but the image does not appear.
when I select all images.. using $('image') I find the image, and I can select it, but still.. it is not visible.
I tried to investigate this issue, but found nothing.
what am I doing wrong??
I found a jQuery plugin that solved my problem jQuery.svg
it has several methods to draw different shapes, including images.
It seems that it adds images by creating a dom node using native JavaScript.. and it works