$ Function
Syntax
Arguments
- eleIdstring
A case-sensitive string representing the ID of the element to find.
- eleId-Nstring
(Optional) One or more additional element IDs to find, separated by commas.
Description
Gets a pointer to one or more HTML elements.
The $() function gets a pointer to elements in the HTML. It takes an arbitrary number of arguments, each a string with the ID of the element you wish to get a pointer to.
If you pass it a single eleId, the function will return a pointer to that element.
If you pass it multiple eleIds, the function will return a Javascript array of the HTML elements.
If an element with the ID specified does not exist, the function will automatically look for an element that has a NAME of the passed in string, and return it.
The $() function is a convenient alternative to the native Javascript document.getElementById() function.
Example
$('firstname').value = 'Fred';
var p = $('lastname');
p.value = 'Smith';
/*Get an array of pointers to elements on the page */
var arr = $('firstame','lastname','city','state','zip');
arr[0].value = 'Fred';
arr[1].value = 'Smith';See Also