javascript - Draw in a SVG that was already drawn -
i want know if it's possible , how draw in drawn svg. let's i've drawn svg something, want add element, without draw again map or modify original cod.
yes, can done. actually, 1 of advantages of svg. here example:
<!doctype html> <html> <head> <title>html5 svg demo</title> </head> <body> <h1>svg demo</h1> <svg id="circle" height="200" xmlns="http://www.w3.org/2000/svg"> <circle id="greencircle" cx="30" cy="30" r="30" fill="green" /> </svg> <script type="text/javascript"> var rect = document.createelementns('http://www.w3.org/2000/svg', 'rect'); rect.setattributens(null,"id", "myrect"); rect.setattributens(null,"fill", "red"); rect.setattributens(null,"stroke", "black"); rect.setattributens(null,"stroke-width", "5"); rect.setattributens(null,"x", "100"); rect.setattributens(null,"y", "100"); rect.setattributens(null,"width", "100"); rect.setattributens(null,"height", "50"); var svg = document.getelementbyid("circle"); svg.appendchild(rect); </script> </body> </html>
Comments
Post a Comment