4 The following functions are treated as Window methods.
6 Function: document.id {#Window:document-id}
7 -------------------------------------------
9 The document.id function has a dual purpose: Getting the element by its id, and making an element in Internet Explorer "grab" all the [Element][] methods.
13 var myElement = document.id(el);
17 1. el - The Element to be extended. Can be one of the following types:
18 * (*element*) The element will be extended if it is not already.
19 * (*string*) A string containing the id of the DOM element desired.
20 * (*object*) If the object has a toElement method, toElement will be called to get the Element.
24 * (*element*) A DOM element.
25 * (*null*) Null if no matching id was found or if toElement did not return an element.
29 #### Get a DOM Element by ID:
31 var myElement = document.id('myElement');
33 #### Get a DOM Element by reference:
35 var div = document.getElementById('myElement');
36 div = document.id(div); // the element with all the Element methods applied.
40 - 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().
41 - In Internet Explorer, the [Element][] is extended the first time document.id is called on it, and all the [Element][] Methods become available.
42 - Browsers with native HTMLElement support, such as Safari, Firefox, and Opera, apply all the [Element][] Methods to every DOM element automatically.
43 - 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.
46 Function: $ {#Window:dollar}
47 ----------------------------
49 The dollar function is an alias for [document:id][] if the $ variable is not set already.
50 However it is not recommended to use more frameworks, the $ variable can be set by another framework or script. MooTools will detect this and determine if it will set the $ function so it will not be overwritten.
54 var myElement = $('myElement');
55 var myElement2 = document.id('myElement');
57 myElement == myElement2; // returns true
62 // Now you can use $ safely in this closure
68 - MooTools Blogpost: [The Dollar Save Mode][]
71 Function: $$ {#Window:dollars}
72 ------------------------------
74 Selects and extends DOM elements. Return an Elements instance.
75 The Element instance returned is an array-like object, supporting every [Array][] method and every [Element][] method.
79 var myElements = $$(argument);
83 * selector - (*string*) A CSS selector
84 * elements - (*elements*), (*collection*) or (*array*) An enumerable list of elements
85 * element, element - (*element*) any number of elements as arguments
89 * (*elements*) - An array-like Elements collection of all the DOM elements matched, extended with [document:id][].
93 #### Get Elements by Their Tag Names:
95 $$('a'); // returns all anchor elements in the page.
97 #### Get an Elements instance by passing multiple elements:
99 $$(element1, element2, element3); // returns an Elements instance containing these 3 elements.
101 #### Convert any array or collection of elements to an Elements instance:
103 $$([element1, element2, element3]); // returns an Elements instance containing these 3 elements.
104 $$(document.getElementsByTagName('a')); // returns an Elements instance containing the result of the getElementsByTagName call.
106 #### Using CSS Selectors:
108 $$('#myElement'); // returns an Elements instance containing only the element with the id 'myElement'.
109 $$('#myElement a.myClass'); // returns an Elements instance of all anchor tags with the class 'myClass' within the DOM element with id 'myElement'.
110 $$('a, b'); // returns an array of all anchor and bold elements in the page.
114 - Since MooTools 1.3 this function does not accept multiple collections or multiple strings as arguments.
115 - If an expression doesn't find any elements, an empty Elements instance will be returned.
116 - The return type of element methods run through [$$][] is always an Elements instance, regardless of the amount of results.
117 - Default Selectors supported are the same as you can find on [W3C CSS3 selectors](http://www.w3.org/TR/css3-selectors/#selectors).
120 Type: Element {#Element}
121 ========================
123 Custom Type to allow all of its methods to be used with any extended DOM Element.
127 Element Method: constructor {#Element:constructor}
128 --------------------------------------------------
130 Creates a new Element of the type passed in.
134 var myEl = new Element(element[, properties]);
138 1. element - (*mixed*) The tag name for the Element to be created or an actual DOM element or a CSS selector.
139 2. properties - (*object*, optional) Calls the Single Argument version of [Element:set][] with the properties object passed in.
143 * (*element*) A new MooTools extended HTML Element.
147 // Creating an new anchor with an Object
148 var myAnchor = new Element('a', {
149 href: 'http://mootools.net',
154 border: '1px solid black'
160 mouseover: function(){
161 alert('mouseovered');
167 var myNewElement = new Element('a.myClass');
171 - [$][], [Element:set][]
175 Element Method: getElement {#Element:getElement}
176 ------------------------------------------------
178 Gets the first descendant element whose tag name matches the tag provided. CSS selectors may also be passed.
182 var myElement = myElement.getElement(tag);
186 1. tag - (*string*) Tag name of the element to find or a CSS Selector.
190 * (*mixed*) If a match is found, the Element will be returned. Otherwise, returns null.
194 var firstDiv = $(document.body).getElement('div');
198 - This method is also available for Document instances.
199 - Default Selectors supported are the same as you can find on [W3C CSS3 selectors](http://www.w3.org/TR/css3-selectors/#selectors).
203 Element Method: getElements {#Element:getElements}
204 --------------------------------------------------
206 Collects all decedent elements whose tag name matches the tag provided. CSS selectors may also be passed.
210 var myElements = myElement.getElements(tag);
214 1. tag - (*string*) String of the tag to match or a CSS Selector.
218 * (*array*) An [Elements][] array of all matched Elements.
222 var allAnchors = $(document.body).getElements('a');
226 - This method is also available for Document instances.
227 - Default Selectors supported are the same as you can find on [W3C CSS3 selectors](http://www.w3.org/TR/css3-selectors/#selectors).
231 Element Method: getElementById {#Element:getElementById}
232 --------------------------------------------------------
234 Gets the element with the specified id found inside the current Element.
238 var myElement = anElement.getElementById(id);
242 1. id - (*string*) The ID of the Element to find.
246 * (*mixed*) If a match is found, returns that Element. Otherwise, returns null.
250 var myChild = $('myParent').getElementById('myChild');
254 - This method is not provided for Document instances as document.getElementById is provided natively.
258 Element Method: set {#Element:set}
259 ----------------------------
261 This is a "dynamic arguments" method. Properties passed in can be any of the 'set' properties in the [Element.Properties][] Object.
265 myElement.set(arguments);
269 - Two Arguments (property, value)
270 1. property - (*string*) The string key from the [Element.Properties][] Object representing the property to set.
271 2. value - (*mixed*) The value to set for the specified property.
272 - One Argument (properties)
273 1. properties - (*object*) Object with its keys/value pairs representing the properties and values to set for the Element (as described below).
277 * (*element*) This Element.
281 #### With Property and Value:
283 $('myElement').set('text', 'text goes here');
284 $('myElement').set('class', 'active');
285 // the 'styles' property passes the object to Element:setStyles.
286 var body = $(document.body).set('styles', {
293 var myElement = $('myElement').set({
294 // the 'styles' property passes the object to Element:setStyles.
298 border: '1px solid #f00'
300 // the 'events' property passes the object to Element:addEvents.
302 click: function(){ alert('click'); },
303 mouseover: function(){ this.addClass('over') }
305 //Any other property uses Element:setProperty.
311 - All the property arguments are passed to the corresponding method of the [Element.Properties][] Object.
312 - If no matching property is found in [Element.Properties][], it falls back to [Element:setProperty][].
313 - Whenever using [Element:setProperty][] to set an attribute, pass in the lowercase, simplified form of the property. For example:
314 - use 'for', not 'htmlFor',
315 - use 'class', not 'className'
316 - use 'frameborder', not 'frameBorder'
322 - [Element][], [Element.Properties][], [Element:setProperty][], [Element:addEvents][], [Element:setStyles][]
326 Element Method: get {#Element:get}
327 ----------------------------------
329 This is a "dynamic arguments" method. Properties passed in can be any of the 'get' properties in the [Element.Properties][] Object.
333 myElement.get(property);
337 1. property - (*string*) The string key from the [Element.Properties][] Object representing the property to get.
341 * (*mixed*) The result of calling the corresponding 'get' function in the [Element.Properties][] Object.
345 #### Using Custom Getters:
347 var tag = $('myDiv').get('tag'); // returns "div".
349 #### Fallback to Element Attributes:
351 var id = $('myDiv').get('id'); // returns "myDiv".
352 var value = $('myInput').get('value'); // returns the myInput element's value.
356 - If the corresponding accessor doesn't exist in the [Element.Properties][] Object, the result of [Element:getProperty][] on the property passed in is returned.
360 - [Element][], [Element.Properties][], [Element:getProperty][]
364 Element Method: erase {#Element:erase}
365 --------------------------------------
367 This is a "dynamic arguments" method. Properties passed in can be any of the 'erase' properties in the [Element.Properties][] Object.
371 myElement.erase(property);
375 1. property - (*string*) The string key from the [Element.Properties][] Object representing the property to erase.
379 * (*mixed*) The result of calling the corresponding 'erase' function in the [Element.Properties][] Object.
383 $('myDiv').erase('id'); //Removes the id from myDiv.
384 $('myDiv').erase('class'); //myDiv element no longer has any class names set.
388 - If the corresponding eraser doesn't exist in the [Element.Properties][] Object, [Element:removeProperty][] is called with the property passed in.
392 - [Element][], [Element.Properties][], [Element:removeProperty][]
396 Element Method: match {#Element:match}
397 --------------------------------------
399 Tests this Element to see if it matches the argument passed in.
403 myElement.match(match);
407 1. match - can be a string or element
408 - (*string*) The tag name to test against this element. Any single CSS selectors may also be passed.
409 - (*element*) An element to match; returns true if this is the actual element passed in.
413 * (*boolean*) If the element matched, returns true. Otherwise, returns false.
417 #### Using a Tag Name:
419 // returns true if #myDiv is a div.
420 $('myDiv').match('div');
422 #### Using a CSS Selector:
424 // returns true if #myDiv has the class foo and is named "bar"
425 $('myDiv').match('.foo[name=bar]');
427 #### Using an Element:
430 $('myDiv').match(el); // returns true
431 $('otherElement').match(el); // returns false
435 Element Method: contains {#Element:contains}
436 --------------------------------------------
438 Checks all descendants of this Element for a match.
443 var result = myElement.contains(el);
447 1. el - (*mixed*) Can be an Element reference or string id.
451 * (*boolean*) Returns true if the element contains passed in Element is a child, otherwise false.
457 <div id="Darth_Vader">
458 <div id="Luke"></div>
463 if ($('Darth_Vader').contains('Luke')) alert('Luke, I am your father.'); //tan tan tannn...
467 Element Method: inject {#Element:inject}
468 ----------------------------------------
470 Injects, or inserts, the Element at a particular place relative to the Element's children (specified by the second the argument).
474 myElement.inject(el[, where]);
478 1. el - (*mixed*) el can be the id of an element or an element.
479 2. where - (*string*, optional: defaults to 'bottom') The place to inject this Element. Can be 'top', 'bottom', 'after', or 'before'.
483 * (*element*) This Element.
489 var myFirstElement = new Element('div', {id: 'myFirstElement'});
490 var mySecondElement = new Element('div', {id: 'mySecondElement'});
491 var myThirdElement = new Element('div', {id: 'myThirdElement'});
495 <div id="myFirstElement"></div>
496 <div id="mySecondElement"></div>
497 <div id="myThirdElement"></div>
499 #### Inject to the bottom:
503 myFirstElement.inject(mySecondElement);
507 <div id="mySecondElement">
508 <div id="myFirstElement"></div>
511 #### Inject to the top:
515 myThirdElement.inject(mySecondElement, 'top');
519 <div id="mySecondElement">
520 <div id="myThirdElement"></div>
521 <div id="myFirstElement"></div>
528 myFirstElement.inject(mySecondElement, 'before');
532 <div id="myFirstElement"></div>
533 <div id="mySecondElement"></div>
539 myFirstElement.inject(mySecondElement, 'after');
543 <div id="mySecondElement"></div>
544 <div id="myFirstElement"></div>
548 [Element:adopt](#Element:adopt), [Element:grab](#Element:grab), [Element:wraps](#Element:wraps)
552 Element Method: grab {#Element:grab}
553 ------------------------------------
555 Works as [Element:inject](#Element:inject), but in reverse.
557 Appends the Element at a particular place relative to the Element's children (specified by the where parameter).
561 myElement.grab(el[, where]);
565 1. el - (*mixed*) el can be the id of an element or an Element.
566 2. where - (*string*, optional: default 'bottom') The place to append this Element. Can be 'top' or 'bottom'.
570 * (*element*) This Element.
577 <div id="child"></div>
582 var mySecondElement = new Element('div#second');
583 $('first').grab(mySecondElement);
588 <div id="child"></div>
589 <div id="second"></div>
594 var mySecondElement = new Element('div#second');
595 myFirstElement.grab(mySecondElement, 'top');
600 <div id="second"></div>
601 <div id="child"></div>
606 [Element:adopt](#Element:adopt), [Element:inject](#Element:inject), [Element:wraps](#Element:wraps)
610 Element Method: adopt {#Element:adopt}
611 --------------------------------------
613 Works like [Element:grab](#Element:grab), but allows multiple elements to be adopted and only appended at the bottom.
615 Inserts the passed element(s) inside the Element (which will then become the parent element).
619 myParent.adopt(el[, others]);
623 1. el - (*mixed*) The id of an element, an Element, or an array of elements.
624 2. others - (*mixed*, optional) One or more additional Elements separated by a comma or as an array.
628 * (*element*) This Element.
634 var myFirstElement = new Element('div', {id: 'myFirstElement'});
635 var mySecondElement = new Element('a', {id: 'mySecondElement'});
636 var myThirdElement = new Element('ul', {id: 'myThirdElement'});
638 myParent.adopt(myFirstElement);
639 myParent2.adopt(myFirstElement, 'mySecondElement');
640 myParent3.adopt([myFirstElement, mySecondElement, myThirdElement]);
645 <div id="myFirstElement" />
648 <div id="myFirstElement" />
652 <div id="myFirstElement" />
659 [Element:grab](#Element:grab), [Element:inject](#Element:inject), [Element:wraps](#Element:wraps)
663 Element Method: wraps {#Element:wraps}
664 --------------------------------------
666 Works like [Element:grab](#Element:grab), but instead of moving the grabbed element from its place, this method moves this Element around its target.
668 The Element is moved to the position of the passed element and becomes the parent.
672 myParent.wraps(el[, where]);
676 1. el - (*mixed*) The id of an element or an Element.
677 2. where - (*string*, optional: default 'bottom') The place to insert the passed in element. Can be 'top' or 'bottom'.
681 * (*element*) This Element.
687 <div id="myFirstElement"></div>
691 var mySecondElement = new Element('div', {id: 'mySecondElement'});
692 mySecondElement.wraps($('myFirstElement'));
696 <div id="mySecondElement">
697 <div id="myFirstElement"></div>
702 Element Method: appendText {#Element:appendText}
703 ------------------------------------------------
705 Works like [Element:grab](#Element:grab), but instead of accepting an id or an element, it only accepts text.
706 A text node will be created inside this Element, in either the top or bottom position.
710 myElement.appendText(text);
714 1. text - (*string*) The text to append.
715 1. where - (*string*, optional: default 'bottom') The position to inject the text to. Values accepted are 'top', 'bottom', 'before' and 'after'.
719 * (*element*) The current Element instance.
725 <div id="myElement">Hey.</div>
729 $('myElement').appendText(' Howdy.');
733 <div id="myElement">Hey. Howdy.</div>
737 Element Method: dispose {#Element:dispose}
738 ------------------------------------------
740 Removes the Element from the DOM.
745 var removedElement = myElement.dispose();
749 * (*element*) This Element. Useful to always grab the return from this function, as the element could be [injected](#Element:inject) back.
755 <div id="myElement"></div>
756 <div id="mySecondElement"></div>
760 $('myElement').dispose();
764 <div id="mySecondElement"></div>
768 - [MDC Element:removeChild](http://developer.mozilla.org/en/docs/DOM:element.removeChild)
772 Element Method: clone {#Element:clone}
773 --------------------------------------
775 Clones the Element and returns the cloned one.
780 var copy = myElement.clone([contents, keepid]);
784 1. contents - (*boolean*, optional: defaults to true) When set to false the Element's contents are not cloned.
785 2. keepid - (*boolean*, optional: defaults to false) When true the cloned Element keeps the id attribute, if present. Same goes for any of the cloned childNodes.
790 * (*element*) The cloned Element.
796 <div id="myElement"></div>
800 // clones the Element and appends the clone after the Element.
801 var clone = $('myElement').clone().inject('myElement','after');
805 <div id="myElement">ciao</div>
810 - The returned Element does not have attached events. To clone the events use [Element:cloneEvents](/Element/Element.Event#Element:cloneEvents).
811 - Values stored in Element.Storage are not cloned.
812 - The clone element and its children are stripped of ids, unless otherwise specified by the keepid parameter.
816 - [Element:cloneEvents](/Element/Element.Event#Element:cloneEvents).
820 Element Method: replaces {#Element:replaces}
821 --------------------------------------------------
823 Replaces the passed Element with Element.
827 var element = myElement.replaces(el);
831 1. el - (*mixed*) A string id representing the Element to be replaced, or an Element reference.
835 * (*element*) This Element.
839 $('myNewElement').replaces($('myOldElement'));
840 //$('myOldElement') is gone, and $('myNewElement') is in its place.
844 - [MDC Element:replaceChild](http://developer.mozilla.org/en/docs/DOM:element.replaceChild)
848 Element Method: hasClass {#Element:hasClass}
849 --------------------------------------------
851 Tests the Element to see if it has the passed in className.
855 var result = myElement.hasClass(className);
859 1. className - (*string*) The class name to test.
863 * (*boolean*) Returns true if the Element has the class, otherwise false.
869 <div id="myElement" class="testClass"></div>
873 $('myElement').hasClass('testClass'); // returns true
877 Element Method: addClass {#Element:addClass}
878 --------------------------------------------
880 Adds the passed in class to the Element, if the Element doesnt already have it.
884 myElement.addClass(className);
888 1. className - (*string*) The class name to add.
892 * (*element*) This Element.
898 <div id="myElement" class="testClass"></div>
902 $('myElement').addClass('newClass');
906 <div id="myElement" class="testClass newClass"></div>
910 Element Method: removeClass {#Element:removeClass}
911 ----------------------------
913 Works like [Element:addClass](#Element:addClass), but removes the class from the Element.
918 myElement.removeClass(className);
922 1. className - (*string*) The class name to remove.
926 * (*element*) This Element.
932 <div id="myElement" class="testClass newClass"></div>
936 $('myElement').removeClass('newClass');
940 <div id="myElement" class="testClass"></div>
944 Element Method: toggleClass {#Element:toggleClass}
945 --------------------------------------------------
947 Adds or removes the passed in class name to the Element, depending on whether or not it's already present.
951 myElement.toggleClass(className, force);
955 1. className - (*string*) The class to add or remove.
956 2. force - (*boolean*, optional) Force the class to be either added or removed
960 * (*element*) This Element.
966 <div id="myElement" class="myClass"></div>
970 $('myElement').toggleClass('myClass');
974 <div id="myElement" class=""></div>
978 $('myElement').toggleClass('myClass');
982 <div id="myElement" class="myClass"></div>
986 Element Method: getPrevious {#Element:getPrevious}
987 --------------------------------------------------
989 Returns the previousSibling of the Element (excluding text nodes).
993 var previousSibling = myElement.getPrevious([match]);
997 1. match - (*string*, optional): A tag name to match the the found element(s) with. A full CSS selector can be passed.
1001 * (*mixed*) The previous sibling Element or null if none found.
1005 Element Method: getAllPrevious {#Element:getAllPrevious}
1006 --------------------------------------------------------
1008 Like [Element:getPrevious][], but returns a collection of all the matched previousSiblings.
1012 Element Method: getNext {#Element:getNext}
1013 ------------------------------------------
1015 As [Element:getPrevious][], but tries to find the nextSibling (excluding text nodes).
1020 var nextSibling = myElement.getNext([match]);
1024 1. match - (*string*, optional): A comma seperated list of tag names to match the found element(s) with. A full CSS selector can be passed.
1028 * (*mixed*) The next sibling Element or null if none found.
1031 Element Method: getAllNext {#Element:getAllNext}
1032 ------------------------------------------------
1034 Like Element.getNext, but returns a collection of all the matched nextSiblings.
1038 Element Method: getFirst {#Element:getFirst}
1039 --------------------------------------------
1041 Gets the first element that matches the passed in expression.
1046 var firstElement = myElement.getFirst([match]);
1050 1. match - (*string*, optional): A full CSS selector to match the found element(s) with.
1054 * (*mixed*) The first found element or null if none found.
1058 Element Method: getLast {#Element:getLast}
1059 ------------------------------------------
1061 Gets the last element that matches the passed in expression.
1065 var lastElement = myElement.getLast([match]);
1069 1. match - (*string*, optional): A full CSS selector to match the found element(s) with.
1073 * (*mixed*) The last found element, or returns null if none found.
1077 Element Method: getParent {#Element:getParent}
1078 ----------------------------------------------
1080 Works as [Element:getPrevious][], but tries to find the parentNode.
1085 var parent = myElement.getParent([match]);
1089 1. match - (*string*, optional): A tag name to match the found element(s) with. A full CSS selector can be passed.
1093 * (*mixed*) The target Element's parent or null if no matching parent is found.
1097 Element Method: getParents {#Element:getParents}
1098 ------------------------------------------------
1100 Like [Element:getParent](#Element:getParent), but returns a collection of all the matched parentNodes up the tree.
1104 Element Method: getSiblings {#Element:getSiblings}
1105 --------------------------------------------------
1107 Like [Element:getAllPrevious][] but returns all Element's previous and next siblings (excluding text nodes). Returns as [Elements][].
1112 var siblings = myElement.getSiblings([match]);
1116 1. match - (*string*, optional): A tag name to match the found element(s) with. A full CSS selector can be passed.
1120 * (*array*) A [Elements](#Elements) array with all of the Element's siblings, except the text nodes.
1124 Element Method: getChildren {#Element:getChildren}
1125 --------------------------------------------------
1127 Returns all the Element's children (excluding text nodes). Returns as [Elements][].
1132 var children = myElement.getChildren([match]);
1136 1. match - (*string*, optional): A tag name to match the found element(s) with. A full CSS selector can be passed.
1140 * (*array*) A [Elements](#Elements) array with all of the Element's children, except the text nodes.
1144 The difference between the methods *getChildren* and *getElements* is that getChildren will only return its direct children while getElements searches for all the Elements in any depth.
1146 Element Method: empty {#Element:empty}
1147 --------------------------------------
1149 Empties an Element of all its children.
1158 * (*element*) This Element.
1164 <div id="myElement">
1171 $('myElement').empty();
1173 ##### Resulting HTML
1175 <div id="myElement"></div>
1179 Element Method: destroy {#Element:destroy}
1180 ------------------------------------------
1182 Empties an Element of all its children, removes and garbages the Element.
1183 Useful to clear memory before the pageUnload.
1187 myElement.destroy();
1195 Element Method: toQueryString {#Element:toQueryString}
1196 ------------------------------------------------------
1198 Reads the child inputs of the Element and generates a query string based on their values.
1203 var query = myElement.toQueryString();
1207 * (*string*) A string representation of a all the input Elements' names and values.
1213 <form id="myForm" action="submit.php">
1214 <input name="email" value="bob@bob.com" />
1215 <input name="zipCode" value="90210" />
1220 $('myForm').toQueryString(); // returns "email=bob@bob.com&zipCode=90210".
1223 Element Method: getSelected {#Element:getSelected}
1224 --------------------------------------------------
1226 Returns the selected options of a select element.
1231 var selected = mySelect.getSelected();
1235 * (*array*) An array of the selected elements.
1241 <select id="country-select" name="country">
1242 <option value="US">United States</option
1243 <option value ="IT">Italy</option>
1248 $('country-select').getSelected(); // returns whatever the user selected.
1252 This method returns an array, regardless of the multiple attribute of the select element.
1253 If the select is single, it will return an array with only one item.
1257 Element Method: getProperty {#Element:getProperty}
1258 --------------------------------------------------
1260 Returns a single element attribute.
1264 var myProp = myElement.getProperty(property);
1268 * property - (*string*) The property to be retrieved.
1272 * (*string*) A string containing the Element's requested property.
1278 <img id="myImage" src="mootools.png" title="MooTools, the compact JavaScript framework" alt="" />
1282 var imgProps = $('myImage').getProperty('src'); // returns: 'mootools.png'.
1286 Element Method: getProperties {#Element:getProperties}
1287 ------------------------------------------------------
1289 Gets multiple element attributes.
1293 var myProps = myElement.getProperties(properties);
1297 * properties - (*strings*) Any number of properties to be retrieved.
1301 * (*object*) An object containing all of the Element's requested properties.
1307 <img id="myImage" src="mootools.png" title="MooTools, the compact JavaScript framework" alt="" />
1311 var imgProps = $('myImage').getProperties('id', 'src', 'title', 'alt');
1312 // returns: { id: 'myImage', src: 'mootools.png', title: 'MooTools, the compact JavaScript framework', alt: '' }
1316 Element Method: setProperty {#Element:setProperty}
1317 --------------------------------------------------
1319 Sets an attribute or special property for this Element.
1324 1. property - (*string*) The property to assign the value passed in.
1325 2. value - (*mixed*) The value to assign to the property passed in.
1329 * (*element*) - This Element.
1335 <img id="myImage" />
1339 $('myImage').setProperty('src', 'mootools.png');
1341 ##### Resulting HTML
1343 <img id="myImage" src="mootools.png" />
1347 - Whenever using [Element:setProperty][] to set an attribute, pass in the lowercase, simplified form of the property. For example:
1348 - use 'for', not 'htmlFor',
1349 - use 'class', not 'className'
1350 - use 'frameborder', not 'frameBorder'
1354 Element Method: setProperties {#Element:setProperties}
1355 ------------------------------------------------------
1357 Sets numerous attributes for the Element.
1362 1. properties - (*object*) An object with key/value pairs.
1366 * (*element*) This Element.
1372 <img id="myImage" />
1376 $('myImage').setProperties({
1377 src: 'whatever.gif',
1378 alt: 'whatever dude'
1381 ##### Resulting HTML
1383 <img id="myImage" src="whatever.gif" alt="whatever dude" />
1387 Element Method: removeProperty {#Element:removeProperty}
1388 --------------------------------------------------------
1390 Removes an attribute from the Element.
1395 myElement.removeProperty(property);
1399 1. property - (*string*) The attribute to remove.
1403 * (*element*) This Element.
1409 <a id="myAnchor" href="#" onmousedown="alert('click');"></a>
1413 //Eww... inline JavaScript is bad! Let's get rid of it.
1414 $('myAnchor').removeProperty('onmousedown');
1416 ##### Resulting HTML
1418 <a id="myAnchor" href="#"></a>
1422 Element Method: removeProperties {#Element:removeProperties}
1423 ------------------------------------------------------------
1425 Removes numerous attributes from the Element.
1430 myElement.removeProperties(properties);
1434 1. properties - (*strings*) The attributes to remove, separated by comma.
1438 * (*element*) This Element.
1444 <a id="myAnchor" href="#" title="hello world"></a>
1448 $('myAnchor').removeProperties('id', 'href', 'title');
1450 ##### Resulting HTML
1455 Element Method: store {#Element:store}
1456 --------------------------------------
1458 Stores an item in the Elements Storage, linked to this Element.
1463 myElement.store(key, value);
1467 1. key - (*string*) The key you want to assign to the stored value.
1468 2. value - (*mixed*) Any value you want to store.
1472 * (*element*) This Element.
1476 $('element').store('someProperty', someValue);
1479 Element Method: retrieve {#Element:retrieve}
1480 --------------------------------------------
1482 Retrieves a value from the Elements storage.
1487 myElement.retrieve(key[, default]);
1491 1. key - (*string*) The key you want to retrieve from the storage.
1492 2. default - (*mixed*, optional) Default value to store and return if no value is stored.
1496 * (*mixed*) The value linked to the key.
1500 $('element').retrieve('someProperty'); // returns someValue (see example above)
1503 Element Method: eliminate {#Element:eliminate}
1504 --------------------------------------------
1506 Eliminates a key from the Elements storage.
1511 myElement.eliminate(key);
1515 1. key - (*string*) The key you want to eliminate from the storage.
1519 * (*mixed*) The element/window/document.
1523 $('element').eliminate('someProperty');
1529 Object: Element.Properties {#Element-Properties}
1530 ==============================================
1532 This Object contains the functions that respond to the first argument passed in [Element:get][], [Element:set][] and [Element:erase][].
1534 ### Adding a Custom Element Property
1536 Element.Properties.disabled = {
1539 return this.disabled;
1542 set: function(value){
1543 this.disabled = !!value;
1544 this.setAttribute('disabled', !!value);
1549 ### Using a Custom Element Property
1551 // gets the "disabled" property
1552 $(element).get('disabled');
1553 // sets the "disabled" property to true, along with the attribute
1554 $(element).set('disabled', true);
1557 ### Using an Object:
1559 Additionally, you can access these custom getters and setters using an object as the parameter for the [set](#Element:set) method.
1564 $(divElement).set({html: '<p>Hello <em>People</em>!</p>', style: 'background:red'});
1566 // for new Elements (works the same as set):
1567 new Element('input', {type: 'checkbox', checked: true, disabled: true});
1572 - Automatically returns the element for setters.
1573 - Since MooTools 1.3 this is a native JavaScript Object and not an instance of the deprecated Hash
1577 Element Property: html {#Element-Properties:html}
1578 -------------------------------------------------
1582 Sets the innerHTML of the Element.
1586 myElement.set('html', [htmlString[, htmlString2[, htmlString3[, ..]]]);
1590 1. Any number of string parameters with HTML.
1594 * (*element*) This Element.
1600 <div id="myElement"></div>
1604 $('myElement').set('html', '<div></div>', '<p></p>');
1606 ##### Resulting HTML
1608 <div id="myElement">
1615 Returns the inner HTML of the Element.
1619 myElement.get('html');
1623 * (*text*) This Element's innerHTML.
1627 Element Property: text {#Element-Properties:text}
1628 -------------------------------------------------
1632 Sets the inner text of the Element.
1636 myElement.set('text', text);
1640 1. text - (*string*) The new text content for the Element.
1644 * (*element*) This Element.
1650 <div id="myElement"></div>
1654 $('myElement').set('text', 'some text');
1655 // the text of myElement is now 'some text'.
1657 ##### Resulting HTML
1659 <div id="myElement">some text</div>
1663 Gets the inner text of the Element.
1667 var myText = myElement.get('text');
1671 * (*string*) The text of the Element.
1677 <div id="myElement">my text</div>
1681 var myText = $('myElement').get('text'); // myText = 'my text'.
1685 Element Property: tag {#Element-Properties:tag}
1686 -----------------------------------------------
1690 Returns the tag name of the Element in lower case.
1694 var myTag = myElement.get('tag');
1698 * (*string*) The tag name in lower case.
1704 <img id="myImage" />
1708 var myTag = $('myImage').get('tag'); // myTag = 'img'
1712 Type: IFrame {#IFrame}
1713 ========================
1715 Custom Type to create and easily work with IFrames.
1719 IFrame Method: constructor {#IFrame:constructor}
1720 ------------------------------------------------
1722 Creates an IFrame HTML Element and extends its window and document with MooTools.
1727 var myIFrame = new IFrame([el][, props]);
1731 1. el - (*mixed*, optional) The id of the IFrame to be converted, or the actual IFrame element. If its not passed, a new IFrame will be created (default).
1732 2. props - (*object*, optional) The properties to be applied to the new IFrame. Same as [Element:constructor](#Element:constructor) props argument.
1736 * (*element*) A new IFrame HTML Element.
1740 var myIFrame = new IFrame({
1742 src: 'http://mootools.net/',
1747 border: '1px solid #ccc'
1752 mouseenter: function(){
1753 alert('Welcome aboard.');
1756 mouseleave: function(){
1761 alert('The iframe has finished loading.');
1771 - If the IFrame already exists and has a different name than id, the name will be made the same as the id.
1772 - An IFrame's window and document will not be extended with MooTools methods.
1776 Type: Elements {#Elements}
1777 ============================
1779 The Elements class allows [Element][] methods to work on an [Elements][] array, as well as [Array][] Methods.
1783 Elements Method: constructor {#Elements:constructor}
1784 ----------------------------------------------------
1789 var myElements = new Elements(elements[, options]);
1793 1. elements - (*mixed*) An array of elements or an HTMLCollection Object.
1797 * (*array*) An array-like Elements collection with the [Element][], [Elements][] and [Array][] methods.
1801 #### Set Every Paragraph's Color to Red:
1803 $$('p').each(function(el){
1804 el.setStyle('color', 'red');
1807 // Because $$('myselector') also accepts Element methods, the below
1808 // example has the same effect as the one above.
1809 $$('p').setStyle('color', 'red');
1812 #### Create Elements From an Array:
1814 var myElements = new Elements(['myElementID', $('myElement'), 'myElementID2', document.getElementById('myElementID3')]);
1819 - In MooTools, every DOM function which returns a collection of nodes (such as [$$][]) returns the nodes as instances of Elements.
1820 - Because Elements is an array-like-object, it accepts all the [Array][] methods, while giving precedence to [Element][] and [Elements][] methods.
1821 - Every node of the Elements instance has all the [Element][] methods.
1825 - [$$][], [$][], [Element][], [Elements][], [Array][]
1829 Elements Method: filter {#Elements:filter}
1830 ----------------------------------------------
1832 Filters a collection of elements by a given tag name. This method will be able to filter by any selector.
1833 It also works like [Array:filter][], by filtering collection of elements with a function.
1838 var filteredElements = elements.filter(selector);
1842 1. selector - (*mixed*) A single CSS selector.
1846 * (*array*) A subset of this [Elements][] instance.
1849 Deprecated Functions {#Deprecated-Functions}
1850 ============================================
1852 Element Method: hasChild {#Deprecated-Functions:hasChild}
1853 ---------------------------------------------------------
1855 This method has been deprecated. Use [Element:contains][] instead.
1859 var myElement = document.id('element1');
1860 var myElement2 = document.id('element2');
1861 myElement !== myElement2 && myElement.contains(element2);
1863 // could be implemented as:
1864 Element.implement('hasChild', function(element){
1865 return this !== element && this.contains(element);
1870 [document:id]: #Window:document-id
1872 [$$]: #Window:dollars
1874 [Array]: /core/Types/Array
1875 [Array:filter]: /core/Types/Array#Array:filter
1878 [Elements]: #Elements
1879 [Element:set]: #Element:set
1880 [Element:get]: #Element:get
1881 [Element:erase]: #Element:erase
1882 [Element:setProperty]: #Element:setProperty
1883 [Element:getProperty]: #Element:getProperty
1884 [Element:removeProperty]: #Element:removeProperty
1885 [Element:getElement]: #Element:getElement
1886 [Element:getElements]: #Element:getElements
1887 [Element.Properties]: #Element-Properties
1888 [Element:getPrevious]: #Element:getPrevious
1889 [Element:getAllPrevious]: #Element:getAllPrevious
1890 [Element:contains]: #Element:contains
1892 [Element:addEvents]: /core/Element/Element.Event#Element:addEvents
1893 [Element:setStyles]: /core/Element/Element.Style#Element:setStyles
1895 [The Dollar Save Mode]: http://mootools.net/blog/2009/06/22/the-dollar-safe-mode/