g(..).readAttribute(attr, [n])

Returns the specified attribute of the nth element in the Gimme Object's internal array; n is optional and default to 0.

Returns: The specified attribute of the nth element in the Gimme Object's internal array.
Params:
  • styleName, required: The name of the desired style property to retrieve (ex: 'href' or 'cols')
  • n, optional (default = 0): The index of the element whose attribute value is to be retrieved.

Examples:
// retrieves the href attribute the element whose id is #yahooLink
var href = g('#yahooLink').readAttribute('href');

// retrieves the made-up "bar" attribute of: <div id = "foo" bar = "uh oh">Foo-Bar</div>
var bar = g('#foo').readAttribute('foo');

// retrieves the rows attribute of the <textarea> whose id is "txtArea"
var rows = g('#txtArea').readAttribute('rows');



Additional Information:
The .readAttribute(..) method will attempt to equalize browser differences (i.e. Browsers like IE "normalizing" href attributes to full paths even when they were not set that way in HTML).

Gimme does a reasonably good job at this, but always be sure to test the results of .readAttribute in all browser to make sure you're getting back the values you expect, as browsers tend to have sharp disagreements in this area.

Last edited Nov 13, 2007 at 7:25 PM by sstchur, version 3

Comments

No comments yet.