getComputedStyle()

Returns an object representing all of the computed styles of an element.

If propertyName is supplied then the associated computed property value is returned. Building an entire computed style object is expensive in Internet Explorer so it is more efficient to fetch properties one at a time.

Syntax

var computedStyle = behavior.getComputedStyle(element);
var computedValue = behavior.getComputedStyle(element, propertyName);

Example

This example retrieves the entire computed style object:

var mybehavior = jsb.behavior.extend({
  isHidden: function(element) {
    var style = this.getComputedStyle(element);
    return style.visibility == "hidden" || style.display == "none";
  }
});

This example retrieves computed style properties as they are needed:

var mybehavior = jsb.behavior.extend({
  isHidden: function(element) {
    return this.getComputedStyle(element, "visibility") == "hidden" ||
      this.getComputedStyle(element, "display") == "none";
  }
});

Notes

This method provides a cross-browser, safe way to perform the W3C equivalent method. Please note that some browsers do not support this method so you should always use the jsb method.

See Also