I use jQuery to add an element to the embedded SVG, for example:
var rect = SVG('rect'); $(rect).attr( { x: left, y: top, width: right - left, height: bottom - top, style: style } ); $(parentElement).append(rect);
parentElement can be, for example, $ ('g: first', svgRoot), where svgRoot refers to an inline SVG element.
function SVG(elementName) { return document.createElementNS('http://www.w3.org/2000/svg', elementName); }
This works well, a new rectangle is displayed in the browser and added to the DOM:

However, this rectangle is not deleted. It is still displayed in the browser and is present in the DOM:
$(rect).remove();
I also tried
rect.parentNode.removeChild(rect);
resulting in the error message "Uncaught TypeError: Unable to call the removeChild method from null".
Do you have any idea how I can fix this? Using jQuery SVG or another plugin / framework in my project is not possible.
javascript jquery html5 svg
sbaltes
source share