Skip to content

Instantly share code, notes, and snippets.

@subtleGradient
Created June 7, 2009 03:35
Show Gist options
  • Select an option

  • Save subtleGradient/125132 to your computer and use it in GitHub Desktop.

Select an option

Save subtleGradient/125132 to your computer and use it in GitHub Desktop.
{
"Function":"$",
"description":"The dollar function has a dual purpose: Getting the element by its id, and making an element in Internet Explorer \"grab\" all the Element methods.",
"Syntax":"var myElement = $(el);",
"Arguments": {
"el":["The Element to be extended.", {
"object":"If the object has a toElement method, toElement will be called to get the Element.",
"string":"A string containing the id of the DOM element desired.",
"element":"The element will be extended if it is not already."
}],
"arg2":["Description", "type"],
"arg2":["Description", {
"type1":"Description",
"type2":"Description"
}]
},
"Returns": {
"null":"Null if no matching id was found or if toElement did not return an element.",
"element":"A DOM element."
},
"Examples": {
"Get a DOM Element by ID":"var myElement = $('myElement');\n",
"Get a DOM Element by reference":"var div = document.getElementById('myElement');\ndiv = $(div); \/\/The element with all the Element methods applied.\n"
},
"Notes": [
"This method is useful when it's unclear if working with an actual element or an id. It also serves as a shorthand for document.getElementById().",
"In Internet Explorer, the Element is extended the first time $ is called on it, and all the Element Methods become available.",
"Browsers with native HTMLElement support, such as Safari, Firefox, and Opera, apply all the Element Methods to every DOM element automatically.",
"Because MooTools detects if an element needs to be extended or not, this function may be called on the same Element many times with no ill effects."
]
}
---
Function: $
description: |
The dollar function has a dual purpose: Getting the element by its id, and making an element in Internet Explorer "grab" all the Element methods.
Syntax: |
var myElement = $(el);
Arguments:
el:
- The Element to be extended.
- object: If the object has a toElement method, toElement will be called to get the Element.
element: The element will be extended if it is not already.
string: A string containing the id of the DOM element desired.
arg2:
- Description
- type
arg3:
- Description
- type1: Description
type2: Description
Returns:
element: A DOM element.
"null": Null if no matching id was found or if toElement did not return an element.
Examples:
Get a DOM Element by ID: |
var myElement = $('myElement');
Get a DOM Element by reference: |
var div = document.getElementById('myElement');
div = $(div); //The element with all the Element methods applied.
Notes:
- This method is useful when it's unclear if working with an actual element or an id. It also serves as a shorthand for document.getElementById().
- In Internet Explorer, the Element is extended the first time $ is called on it, and all the Element Methods become available.
- Browsers with native HTMLElement support, such as Safari, Firefox, and Opera, apply all the Element Methods to every DOM element automatically.
- Because MooTools detects if an element needs to be extended or not, this function may be called on the same Element many times with no ill effects.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment