Reputation: 1624
I tried using jquery's attr function to extract the id from an object generated as such:
var draw = SVG (parent).size (100,100)
but
draw.attr ('id')
doesn't work. How do I get the id from draw?
Upvotes: 1
Views: 676
Reputation: 2061
The draw object is an SVG object. In order to use jQuery function it needs to be converted.
var draw = SVG (parent).size (100,100)
To convert it the first thing we need is the actual DOM-node, not the SVG object. draw.node
is the reference to the actual SVG DOM-node. Once we have the DOM-node we convert that into a jQuery object $(draw.node)
.
Now when we have the jQuery object we can for instance use the jQuery attr
function
$(draw.node).attr(.id...)
However, it is possible to do this with SVG.js as well, and these are two ways to do it. I have included a fiddle as proof of concept.
draw.id()
or
draw.attr('id')
Here is a fiddle which show the one of these whays, http://jsfiddle.net/8AJ64/
Upvotes: 3