getBoundingClientRect()

Returns an object whose left, top, right and bottom properties describe the text rectangle of the supplied element relative to the viewport.

Syntax

var rect = behavior.getBoundingClientRect(element);

Example

var mybehavior = jsb.behavior.extend({
  onmousedown: function(element) {
    this.showDropDown(element);
  },

  showDropDown: function(element) {
    var rect = this.getBoundingClientRect(element);
    var dropdown = new MenuList("#postal-codes");
    // show the dropdown box immediately below the element
    dropdown.show(rect.left, rect.bottom, rect.width, "auto");
  }
});

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