JavaScript

$ga Function

Syntax

$ga(element, attribute)

Arguments

elementelement objectstringarray

A string with the ID or NAME of the element, a pointer to an HTML element, or an array of either of the previous.

attributestringarray of strings

A string with the name of the attribute you wish to read, or an array of attribute names.

Returns

Valuearray

Returns the value of the specified attributes for the element(s).

Description

The $ga() function retrieves an attribute or multiple attributes from a single element or multiple elements.

Discussion

If you pass in a single element, and a single attribute name, the return value will be a string with the attribute value. If you pass in a single element and an array of attributes, the return value will be an array of attribute values. If you pass in an array of elements and an array of attributes, the return value will be an array of arrays of attributes - each top level entry in the array being an array of values for the corresponding element passed in.

Example

/*This example reads the value of a built-in attribute. Since the attribute is built-in, it could also have been read directly.*/
alert($ga('firstname','title'));
/*Now, read the attribute directly (which we can do, since 'title' is a built-in attribute)*/
alert($('firstname').title);
 
/*The $ga() function's primary purpose is to read user-defined attributes. Assume that want to read the value of an attribute called 'fieldIsDirty'.*/
alert($ga('firstname','fieldIsDirty'));
 
/*$ga() returns an array if you pass it an array of IDs*/
var fieldArray = ['firstname','lastname','company'];
var arr = $ga(fieldArray,'fieldIsDirty');
 
/*Now, loop through the array and report on which elements are dirty.*/
for(var i = 0;i<arr.length;i++) {
    if(arr[i] == 'yes') alert(fieldArray[i] + ' is dirty');
}
Use {dialog.object}.getPointer() to get the DOM element for a control.

See Also