You're using:
y.setAttribute('xlink:href', '#wtf')
That's wrong. Welcome to XML namespaces!
You need to use setAttributeNS with the right namespace:
"http://www.w3.org/1999/xlink".
For what it's worth, a tool like DOM Inspector would have told you this.
Firebug, sadly, doesn't seem to expose that information.
-Boris
You may also find this doc useful: