/    Sign up×
Community /Pin to ProfileBookmark

SVG and USE / DEFS with JS

I am been playing with this for a while now and I cant get my path to show up, I can manually put it in a use element and it works great but I cant generate one with JS. any advice is greatly appreciated.

[CODE]
<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>
<svg
id=”svgContainer”
xmlns=”http://www.w3.org/2000/svg”
xmlns:xlink=”http://www.w3.org/2000/xlink/namespace/”
width=”1000″
height=”1000″
version=”1.1″
onload=”create_seeds(evt)”>

<defs><path id=”leaf” fill=”#FFFF00″ d=”M67.105,0.366c99.521,92.793,104.694,248.709,11.553,348.604C-20.863,256.177-26.028,100.253,67.105,0.366z”/></defs>

<script>
<![CDATA[

function create_seeds() {
var mySvg = document.getElementById(“gElement”);
use2 = document.createElement(“use”);
use2.setAttribute(“x”, 30);
use2.setAttribute(“y”, 30);
use2.setAttributeNS(“http://www.w3.org/2000/xlink/namespace/”,”xlink:href”,”#leaf”);
mySvg.appendChild(use2);
}

]]>
</script>

<g id=”gElement”></g>

</svg> [/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@fnsnoopauthorJul 03.2011 — I am currently backtracking and now my path wont even work in the a use element. maybe this is the core of the problem.

[CODE]
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
"http://www.w3.org/TR/SVG/DTD/svg10.dtd">
<svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg"

xmlns:xlink="http://www.w3.org/2002/xlink/namespace">
<defs><path id="leaf" fill="#FFFF00" d="M67.105,0.366c99.521,92.793,104.694,248.709,11.553,348.604C-20.863,256.177-26.028,100.253,67.105,0.366 z"/></defs>
<use xlink:href="#leaf" x="0" y="0" />

</svg>

[/CODE]
×

Success!

Help @fnsnoop spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...