g(..).getAncestor(dist, [n])

Retrieves a DOM element ancestor of the nth element in the Gimme Object's internal array

Returns: The DOM element that is an ancestor dist "generations" removed from the nth element in the Gimme Object's internal array.
Params:
  • dist, required: A positive non-zero integer indicating the distance (or "generatinos") from the nth element in the Gimme Object's internal array.
  • n, optional (default = 0): An integer value between 0 and g(..).length - 1 inclusive, which specifies the index of the element whose ancestor is to be retrieved.

Examples:
// retrieves the ancestor one "generation" removed from #main (this is equivalent to g('#main').parent())
var parent = g('#main').getAncestor(1);

// retrieves the ancestor five "generations" removed (assuming one exists) from the 3rd <p> element on the page.
var ancient = g('p').getAncestor(5, 2);

Last edited Jun 20, 2007 at 6:41 AM by sstchur, version 3

Comments

No comments yet.