1

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;

        }
V31
  • 7,626
  • 3
  • 26
  • 44
knowledge
  • 941
  • 1
  • 11
  • 26
  • have you put console.log in both if and else clause? – V31 Sep 12 '14 at 07:14
  • Yes, i put a log in it and if I do console.log(resultSet.id) "setid" is shown (in else). But the if condition stays false (because I cant see a console.log in this case) – knowledge Sep 15 '14 at 07:53

1 Answers1

0

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.

Mithun Satheesh
  • 27,240
  • 14
  • 77
  • 101