Returns: The nth DOM element from the Gimme Object's internal array.
  • n, optional (default = 0): An integer value between 0 and g(..).entities.length - 1, inclusive.

// thirdDiv will be the 3rd <div> element on the page
var thirdDiv = g('div').element(2);

// height will be the .offsetHeight of the 1st <div> element on the page (no integer specified when calling .element(..), so defaults to 0).
var height = g('div').element().offsetHeight;

// adds a custom (non-standard) attribute to the 1st <span> element on the page: foo = "bar"
g('span').element().setAttribute('foo', 'bar');

// trying to access the 9,875th <p> element will most likely result in null (unless there actually are 9,876 <p> elements on the page)
var oops = g('p').element(9876);

Last edited Jun 4, 2007 at 11:00 PM by sstchur, version 7


No comments yet.