Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
152
rated 0 times [  154] [ 2]  / answers: 1 / hits: 80659  / 14 Years ago, thu, september 9, 2010, 12:00:00

In HTML, I can clear a <div> element with this command:



div.innerHTML = ;


Is there an equivalent if I have an <svg> element? I can't find an innerHTML nor innerXML or even innerSVG method.



I know the SVG DOM is a superset of the XML DOM, so I know I can do something like this:



while (svg.lastChild) {
svg.removeChild(svg.lastChild);
}


But this is both tedious and slow. Is there a faster or easier way to clear an SVG element?


More From » xml

 Answers
12

You already gave one answer: you can always just loop over all children and remove them. If you think that you have too many child nodes then maybe you want to replace the svg node by an empty one. If your svg node has some attributes you may use a tag where you place all the child nodes and then just replace the node with an empty one.


[#95677] Saturday, September 4, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dylondaytond

Total Points: 92
Total Questions: 88
Total Answers: 96

Location: China
Member since Fri, Jan 15, 2021
3 Years ago
dylondaytond questions
Tue, Jun 22, 21, 00:00, 3 Years ago
Thu, May 7, 20, 00:00, 4 Years ago
;