Leem
Leem

Reputation: 18318

Raphael.js how to store the name in each element?

I have rendered several rectangulars in Raphael.js. I would like to give each of the rectangular a name, and store the name to each of them. How to do in Raphael?

For example:

var r1 = paper.rect(10, 10, 50, 50); //name it 'car'
var r2 = paper.rect(10, 10, 50, 50); //name it 'plane'
var r3 = paper.rect(10, 10, 50, 50); //name it 'bike'

then, in future, I can distinguish them by check the name, like r1.attr('name')=='car'

How to add new attribute to store the names then?

Upvotes: 0

Views: 1041

Answers (1)

Potherca
Potherca

Reputation: 14590

Why not just add an ID to the DOM object using .node?

var r1,r2,r3;

r1 = paper.rect(10, 10, 50, 50);
r1.node.id = 'car'

r2 = paper.rect(10, 10, 50, 50);
r2.node.id = 'plane'

r3 = paper.rect(10, 10, 50, 50);
r3.node.id = 'bike'

Upvotes: 1

Related Questions