====== The Dollar Function ====== Have you ever used //document.getElementById('id')//? You know that one function that gets an Element from the DOM with an ID? In MooTools, there is a shortcut for that very function, and it does something extra. var myElement = $('id'); ===== Discussion ===== The dollar function, or //$//, is a shortcut to document.getElementById. It also adds methods to the element you call it on. (That doesn't mean much right now, but keep it in mind.) * A shortcut for //document.getElementById//. * Extends **Element(s)** to have the MooTools Element Methods. * Universal. The leading popular JavaScript Libraries, such as [[http://docs.jquery.com/Core/jQuery#expressioncontext|jQuery]] and [[http://www.prototypejs.org/api/utility#method-$|Prototype]] both use **$** for shortcuts to //document.getElementById//. ===== The Dollar Function Syntax ===== /* The Dollar Function Syntax */ var myElement = $('title'); myElement.set('html', "Changed!"); The example above sets the html of the element with the ID of //title//. The Syntax is very simple for this simple function. You can use it directly, or set a variable to it as in the syntax example. In MooTools, you use this often when working with things that you know exist either by design or elements you made. ===== Documentation Sources ===== You can read the [[http://developer.mozilla.org/en/docs/DOM:document.getElementById|MDC for getElementById]]. You can also read the [[http://clientside.cnet.com/wiki/mootorial/03-native#section|Mootorial for $]]. Continue to [[The Dollars Function]]