The Prototype $() function

The dollar function is one of the Prototype Utility Function. $() is the most frequently used prototype’s function. basically it was used to refer an element in the HTML page. The function is quickly shorthand for getElementById.

The usual function identifying an element is:
document.getElementById("element_id")

The $() function reduces the code to:
$("element_id")

For example, you can set the CSS text color with this code:
$("element_id").style.color = "#ffffff";

Or, the “Prototype way”:
$("id_of_element").setStyle({color: '#ffffff'});

July 20th, 2008 by Admin