setStyle()
Sets the properties of an element’s style object.
Syntax
behavior.setStyle(element, propertyName, value [, important]);
or:
behavior.setStyle(element, properties);
Example
var mybehavior = jsb.behavior.extend({ onmouseover: function(element) { this.highlight(element); }, highlight: function(element) { this.setStyle(element, { color: "red", backgroundColor: "white", opacity: 0.5 }); } });
This example shows how to set the important
flag:
var mybehavior = jsb.behavior.extend({ onmouseover: function(element) { this.setStyle(element, "backgroundColor", "yellow", true); } });
Notes
This method provides a cross-browser, safe way to update the style property.
Most of the time you can just directly assign style properties. You should use this
method to assign styles that are not supported across all browser platforms
(e.g opacity
) or to set the important
flag.