rafael js getbyid doesn't work

57 Views Asked by At

I will check if an element with a certain id (which I named "setid") exists. If not create it and set the id. Unfortunately this doesn't work. Where is the error?

Thanks in advance. Alex

var resultSet;
var setId = "setid";
if(paper.getById(setId) != null) {
            resultSet = paper.getById(setId); 
            resultSet.clear();
            resultSet = paper.set(); 
            resultSet.id =setId;
        }
        else {
            resultSet = paper.set(); 
            resultSet.id = setId;

        }
1

There are 1 best solutions below

0
Mithun Satheesh On

getById wont work for sets. It will work only for elements which are actually rendered on the markup. Set is never rendered in markup unlike groups in SVG. You can see the set implemetation in raphael here.

You can see the implementation of getById in rapheal source. Its just looping from first to last element present on the paper. So the set we made will not come in as it is not a node in the paper.