I guess your problem is resolved already but if you want to know the problem with your original code, there were two:
1. 'style' is a property of an HTML DOM element, however sym.$("myRectangle") would return a wrapper over the same. To access the underlying element, use sym.$("myRectangle").get(0) or sym.$("myRectangle")[0]. In most of the cases, you should be able to find a wrapper function to avoid this direct access, in this case '.css', which can be used as shown above.
2. rgb is not a function, if you want to set the style.backgroundColor the value should be a string. You will have to do string concatenation.
Although not very elegant but any of the following should work:
sym.$("mySquare")[0].style.backgroundColor = "rgb(" + randR + "," + randG + "," + randB + ")"; | |
sym.$("mySquare").css("background-color", "rgb(" + randR + "," + randG + "," + randB + ")"); |
-Dharmendra