g.attr({id:"gid"})
should be the correct way - how are you validating that no id appears?
The code below was typed in the Chrome JavaScript console and verifies using .outerSVG()
as well as inspection on the Elements tab.
Snap.version
"0.2.0"
var g = s.g()
undefined
g.attr({id:"gid"})
Element {id: "Shq33m2ni13", node: g#gid, paper: Element, type: "g", anims: Object…}
g.outerSVG()
"<g id="gid"/>"
Notice that version is 0.2.0
which I got from the adobe-webplatform / Snap.svg GitHub repo. If you have to use 0.1.0
, look at apply ID to a snap.svg graphic which uses the undocumented node
property.
g.node.id = 'gid';