Assuming this:
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("svg").append('<circle cx="100" cy="50" r="40" stroke="black" stroke-width="2" fill="red"/>');
});
</script>
</head>
<body>
<svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 100" width="200px" height="100px">
</svg>
</body>
Why don't I see anything?
JQuery can't append elements to
<svg>
(it does seem to add them in the DOM explorer, but not on the screen).One workaround is to append an
<svg>
with all of the elements that you need to the page, and then modify the attributes of the elements using.attr()
.http://jsfiddle.net/8FBjb/1/
This is working for me today with FF 57:
Makes: