Update
I raised an issue on GitHub and it looks like this will be fixed in the next release. For now, on the development branch, you can use Element.attr
:
var draw = Snap(100, 75);
draw.attr({ id: 'graphic_1' });
I'm leaving the original answer below because:
- at time of writing, this doesn't work in the master (release) version; and
- the technique described for directly accessing the underlying DOM node might be useful to others in future, or those using an older version of Snap.svg.
It's not documented, but internally Snap.svg stores the DOM node in a property called node
. Thus, you can set the ID of the canvas like so:
draw.node.id = 'graphic_1';
Alternatively, if you would prefer to avoid undocumented techniques, you could create an element with the ID that you want first and use that directly:
<svg id="graphic_1" xmlns="http://www.w3.org/2000/svg" version="1.1" width="100" height="75"></svg>
var draw = Snap("#graphic_1");