I’m trying to set then get an attribute from a Raphael rectangle, but I’m getting “undefined”. I’ve tried a number of variations, but nothing is working. Can someone tell me please what I’m doing wrong?
var $belo_victoria = paper.rect(383.281, 557.583, 59.001, 82.303);
$belo_victoria.attr({ "fill": "#722364",
"transform": "T97,123r35",
"pid": "28B23" });
console.log($belo_victoria.pid);
There’s no guarantee that Raphael attributes will be available directly as properties on a given Raphael-managed element — best practices would suggest using the
Element.data method instead. Like this: