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 Safe 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 Because the element name is parsed as a CSS selector, colons in namespaced tags have to be escaped. So `new Element('fb\:name)` becomes `<fb:name>`.
175 - [$][], [Element:set][]
179 Element Method: getElement {#Element:getElement}
180 ------------------------------------------------
182 Gets the first descendant element whose tag name matches the tag provided. CSS selectors may also be passed.
186 var myElement = myElement.getElement(tag);
190 1. tag - (*string*) Tag name of the element to find or a CSS Selector.
194 * (*mixed*) If a match is found, the Element will be returned. Otherwise, returns null.
198 var firstDiv = $(document.body).getElement('div');
202 - This method is also available for Document instances.
203 - Default Selectors supported are the same as you can find on [W3C CSS3 selectors](http://www.w3.org/TR/css3-selectors/#selectors).
207 Element Method: getElements {#Element:getElements}
208 --------------------------------------------------
210 Collects all decedent elements whose tag name matches the tag provided. CSS selectors may also be passed.
214 var myElements = myElement.getElements(tag);
218 1. tag - (*string*) String of the tag to match or a CSS Selector.
222 * (*array*) An [Elements][] array of all matched Elements.
226 var allAnchors = $(document.body).getElements('a');
230 - This method is also available for Document instances.
231 - Default Selectors supported are the same as you can find on [W3C CSS3 selectors](http://www.w3.org/TR/css3-selectors/#selectors).
235 Element Method: getElementById {#Element:getElementById}
236 --------------------------------------------------------
238 Gets the element with the specified id found inside the current Element.
242 var myElement = anElement.getElementById(id);
246 1. id - (*string*) The ID of the Element to find.
250 * (*mixed*) If a match is found, returns that Element. Otherwise, returns null.
254 var myChild = $('myParent').getElementById('myChild');
258 - This method is not provided for Document instances as document.getElementById is provided natively.
262 Element Method: set {#Element:set}
263 ----------------------------
265 This is a "dynamic arguments" method. Properties passed in can be any of the 'set' properties in the [Element.Properties][] Object.
269 myElement.set(arguments);
273 - Two Arguments (property, value)
274 1. property - (*string*) The string key from the [Element.Properties][] Object representing the property to set.
275 2. value - (*mixed*) The value to set for the specified property.
276 - One Argument (properties)
277 1. properties - (*object*) Object with its keys/value pairs representing the properties and values to set for the Element (as described below).
281 * (*element*) This Element.
285 #### With Property and Value:
287 $('myElement').set('text', 'text goes here');
288 $('myElement').set('class', 'active');
289 // the 'styles' property passes the object to Element:setStyles.
290 var body = $(document.body).set('styles', {
297 var myElement = $('myElement').set({
298 // the 'styles' property passes the object to Element:setStyles.
302 border: '1px solid #f00'
304 // the 'events' property passes the object to Element:addEvents.
306 click: function(){ alert('click'); },
307 mouseover: function(){ this.addClass('over'); }
309 //Any other property uses Element:setProperty.
315 - All the property arguments are passed to the corresponding method of the [Element.Properties][] Object.
316 - If no matching property is found in [Element.Properties][], it falls back to [Element:setProperty][].
317 - Whenever using [Element:setProperty][] to set an attribute, pass in the lowercase, simplified form of the property. For example:
318 - use 'for', not 'htmlFor',
319 - use 'class', not 'className'
320 - use 'frameborder', not 'frameBorder'
326 - [Element][], [Element.Properties][], [Element:setProperty][], [Element:addEvents][], [Element:setStyles][]
330 Element Method: get {#Element:get}
331 ----------------------------------
333 This is a "dynamic arguments" method. Properties passed in can be any of the 'get' properties in the [Element.Properties][] Object.
337 myElement.get(property);
341 1. property - (*string*) The string key from the [Element.Properties][] Object representing the property to get.
345 * (*mixed*) The result of calling the corresponding 'get' function in the [Element.Properties][] Object.
349 #### Using Custom Getters:
351 var tag = $('myDiv').get('tag'); // returns "div".
353 #### Fallback to Element Attributes:
355 var id = $('myDiv').get('id'); // returns "myDiv".
356 var value = $('myInput').get('value'); // returns the myInput element's value.
360 - If the corresponding accessor doesn't exist in the [Element.Properties][] Object, the result of [Element:getProperty][] on the property passed in is returned.
364 - [Element][], [Element.Properties][], [Element:getProperty][]
368 Element Method: erase {#Element:erase}
369 --------------------------------------
371 This is a "dynamic arguments" method. Properties passed in can be any of the 'erase' properties in the [Element.Properties][] Object.
375 myElement.erase(property);
379 1. property - (*string*) The string key from the [Element.Properties][] Object representing the property to erase.
383 * (*mixed*) The result of calling the corresponding 'erase' function in the [Element.Properties][] Object.
387 $('myDiv').erase('id'); //Removes the id from myDiv.
388 $('myDiv').erase('class'); //myDiv element no longer has any class names set.
392 - If the corresponding eraser doesn't exist in the [Element.Properties][] Object, [Element:removeProperty][] is called with the property passed in.
396 - [Element][], [Element.Properties][], [Element:removeProperty][]
400 Element Method: match {#Element:match}
401 --------------------------------------
403 Tests this Element to see if it matches the argument passed in.
407 myElement.match(match);
411 1. match - can be a string or element
412 - (*string*) The tag name to test against this element. Any single CSS selectors may also be passed.
413 - (*element*) An element to match; returns true if this is the actual element passed in.
417 * (*boolean*) If the element matched, returns true. Otherwise, returns false.
421 #### Using a Tag Name:
423 // returns true if #myDiv is a div.
424 $('myDiv').match('div');
426 #### Using a CSS Selector:
428 // returns true if #myDiv has the class foo and is named "bar"
429 $('myDiv').match('.foo[name=bar]');
431 #### Using an Element:
434 $('myDiv').match(el); // returns true
435 $('otherElement').match(el); // returns false
439 Element Method: contains {#Element:contains}
440 --------------------------------------------
442 Checks all descendants of this Element for a match.
447 var result = myElement.contains(el);
451 1. el - (*mixed*) Can be an Element reference or string id.
455 * (*boolean*) Returns true if the element contains passed in Element is a child, otherwise false.
461 <div id="Darth_Vader">
462 <div id="Luke"></div>
467 if ($('Darth_Vader').contains('Luke')) alert('Luke, I am your father.'); //tan tan tannn...
471 Element Method: inject {#Element:inject}
472 ----------------------------------------
474 Injects, or inserts, the Element at a particular place relative to the Element's children (specified by the second the argument).
478 myElement.inject(el[, where]);
482 1. el - (*mixed*) el can be the id of an element or an element.
483 2. where - (*string*, optional: defaults to 'bottom') The place to inject this Element. Can be 'top', 'bottom', 'after', or 'before'.
487 * (*element*) This Element.
493 var myFirstElement = new Element('div', {id: 'myFirstElement'});
494 var mySecondElement = new Element('div', {id: 'mySecondElement'});
495 var myThirdElement = new Element('div', {id: 'myThirdElement'});
499 <div id="myFirstElement"></div>
500 <div id="mySecondElement"></div>
501 <div id="myThirdElement"></div>
503 #### Inject to the bottom:
507 myFirstElement.inject(mySecondElement);
511 <div id="mySecondElement">
512 <div id="myFirstElement"></div>
515 #### Inject to the top:
519 myThirdElement.inject(mySecondElement, 'top');
523 <div id="mySecondElement">
524 <div id="myThirdElement"></div>
525 <div id="myFirstElement"></div>
532 myFirstElement.inject(mySecondElement, 'before');
536 <div id="myFirstElement"></div>
537 <div id="mySecondElement"></div>
543 myFirstElement.inject(mySecondElement, 'after');
547 <div id="mySecondElement"></div>
548 <div id="myFirstElement"></div>
552 [Element:adopt](#Element:adopt), [Element:grab](#Element:grab), [Element:wraps](#Element:wraps)
556 Element Method: grab {#Element:grab}
557 ------------------------------------
559 Works as [Element:inject](#Element:inject), but in reverse.
561 Appends the Element at a particular place relative to the Element's children (specified by the where parameter).
565 myElement.grab(el[, where]);
569 1. el - (*mixed*) el can be the id of an element or an Element.
570 2. where - (*string*, optional: default 'bottom') The place to append this Element. Can be 'top', 'bottom', 'before' or 'after'.
574 * (*element*) This Element.
581 <div id="child"></div>
586 var mySecondElement = new Element('div#second');
587 $('first').grab(mySecondElement);
592 <div id="child"></div>
593 <div id="second"></div>
598 var mySecondElement = new Element('div#second');
599 myFirstElement.grab(mySecondElement, 'top');
604 <div id="second"></div>
605 <div id="child"></div>
610 [Element:adopt](#Element:adopt), [Element:inject](#Element:inject), [Element:wraps](#Element:wraps)
614 Element Method: adopt {#Element:adopt}
615 --------------------------------------
617 Works like [Element:grab](#Element:grab), but allows multiple elements to be adopted and only appended at the bottom.
619 Inserts the passed element(s) inside the Element (which will then become the parent element).
623 myParent.adopt(el[, others]);
627 1. el - (*mixed*) The id of an element, an Element, or an array of elements.
628 2. others - (*mixed*, optional) One or more additional Elements separated by a comma or as an array.
632 * (*element*) This Element.
638 var myFirstElement = new Element('div#first');
639 var mySecondElement = new Element('p#second');
640 var myThirdElement = new Element('ul#third');
641 var myFourthElement = new Element('a#fourth');
643 var myParentElement = new Element('div#parent');
645 myFirstElement.adopt(mySecondElement);
646 mySecondElement.adopt('third', myFourthElement);
648 myParent3.adopt([myFirstElement, new Element('span#another')]);
657 <span id="another"></span>
662 [Element:grab](#Element:grab), [Element:inject](#Element:inject), [Element:wraps](#Element:wraps)
666 Element Method: wraps {#Element:wraps}
667 --------------------------------------
669 Works like [Element:grab](#Element:grab), but replaces the element in its place, and then appends the replaced element in the location specified inside the this element.
673 myParent.wraps(el[, where]);
677 1. el - (*mixed*) The id of an element or an Element.
678 2. where - (*string*, optional: default 'bottom') The place to insert the passed in element. Can be 'top' or 'bottom'.
682 * (*element*) This Element.
688 <div id="first"></div>
692 var mySecondElement = new Element('div#second').wraps('first');
697 <div id="first"></div>
702 <div id="first"></div>
704 <div id="child"></div>
709 $('second').wraps('first');
714 <div id="child"></div>
715 <div id="first"></div>
720 $('second').wraps('first', 'top');
725 <div id="first"></div>
726 <div id="child"></div>
729 Element Method: appendText {#Element:appendText}
730 ------------------------------------------------
732 Works like [Element:grab](#Element:grab), but instead of accepting an id or an element, it only accepts text.
733 A text node will be created inside this Element, in either the top or bottom position.
737 myElement.appendText(text[, where]);
741 1. text - (*string*) The text to append.
742 1. where - (*string*, optional: default 'bottom') The position to inject the text to. Values accepted are 'top', 'bottom', 'before' and 'after'.
746 * (*element*) The current Element instance.
752 <div id="myElement">Hey.</div>
756 $('myElement').appendText(' Howdy.');
760 <div id="myElement">Hey. Howdy.</div>
764 Element Method: dispose {#Element:dispose}
765 ------------------------------------------
767 Removes the Element from the DOM.
772 var removedElement = myElement.dispose();
776 * (*element*) This Element. Useful to always grab the return from this function, as the element could be [injected](#Element:inject) back.
782 <div id="myElement"></div>
783 <div id="mySecondElement"></div>
787 $('myElement').dispose();
791 <div id="mySecondElement"></div>
795 - [MDC Element:removeChild][]
799 Element Method: clone {#Element:clone}
800 --------------------------------------
802 Clones the Element and returns the cloned one.
807 var copy = myElement.clone([contents, keepid]);
811 1. contents - (*boolean*, optional: defaults to true) When set to false the Element's contents are not cloned.
812 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.
817 * (*element*) The cloned Element.
823 <div id="myElement">ciao</div>
827 // clones the Element and appends the clone after the Element.
828 var clone = $('myElement').clone().inject('myElement','after');
832 <div id="myElement">ciao</div>
837 - The returned Element does not have attached events. To clone the events use [Element:cloneEvents](/Element/Element.Event#Element:cloneEvents).
838 - Values stored in Element.Storage are not cloned.
839 - The clone element and its children are stripped of ids, unless otherwise specified by the keepid parameter.
843 - [Element:cloneEvents](/Element/Element.Event#Element:cloneEvents).
847 Element Method: replaces {#Element:replaces}
848 --------------------------------------------------
850 Replaces the passed Element with Element.
854 var element = myElement.replaces(el);
858 1. el - (*mixed*) A string id representing the Element to be replaced, or an Element reference.
862 * (*element*) This Element.
866 $('myNewElement').replaces($('myOldElement'));
867 //$('myOldElement') is gone, and $('myNewElement') is in its place.
871 - [MDC Element:replaceChild][]
875 Element Method: hasClass {#Element:hasClass}
876 --------------------------------------------
878 Tests the Element to see if it has the passed in className.
882 var result = myElement.hasClass(className);
886 1. className - (*string*) The class name to test.
890 * (*boolean*) Returns true if the Element has the class, otherwise false.
896 <div id="myElement" class="testClass"></div>
900 $('myElement').hasClass('testClass'); // returns true
904 Element Method: addClass {#Element:addClass}
905 --------------------------------------------
907 Adds the passed in class to the Element, if the Element doesnt already have it.
911 myElement.addClass(className);
915 1. className - (*string*) The class name to add.
919 * (*element*) This Element.
925 <div id="myElement" class="testClass"></div>
929 $('myElement').addClass('newClass');
933 <div id="myElement" class="testClass newClass"></div>
937 Element Method: removeClass {#Element:removeClass}
938 ----------------------------
940 Works like [Element:addClass](#Element:addClass), but removes the class from the Element.
945 myElement.removeClass(className);
949 1. className - (*string*) The class name to remove.
953 * (*element*) This Element.
959 <div id="myElement" class="testClass newClass"></div>
963 $('myElement').removeClass('newClass');
967 <div id="myElement" class="testClass"></div>
971 Element Method: toggleClass {#Element:toggleClass}
972 --------------------------------------------------
974 Adds or removes the passed in class name to the Element, depending on whether or not it's already present.
978 myElement.toggleClass(className, force);
982 1. className - (*string*) The class to add or remove.
983 2. force - (*boolean*, optional) Force the class to be either added or removed
987 * (*element*) This Element.
993 <div id="myElement" class="myClass"></div>
997 $('myElement').toggleClass('myClass');
1001 <div id="myElement" class=""></div>
1005 $('myElement').toggleClass('myClass');
1007 ##### Resulting HTML
1009 <div id="myElement" class="myClass"></div>
1013 Element Method: getPrevious {#Element:getPrevious}
1014 --------------------------------------------------
1016 Returns the previousSibling of the Element (excluding text nodes).
1020 var previousSibling = myElement.getPrevious([match]);
1024 1. match - (*string*, optional): A tag name to match the the found element(s) with. A full CSS selector can be passed.
1028 * (*mixed*) The previous sibling Element or null if none found.
1032 Element Method: getAllPrevious {#Element:getAllPrevious}
1033 --------------------------------------------------------
1035 Like [Element:getPrevious][], but returns a collection of all the matched previousSiblings.
1039 Element Method: getNext {#Element:getNext}
1040 ------------------------------------------
1042 As [Element:getPrevious][], but tries to find the nextSibling (excluding text nodes).
1047 var nextSibling = myElement.getNext([match]);
1051 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.
1055 * (*mixed*) The next sibling Element or null if none found.
1058 Element Method: getAllNext {#Element:getAllNext}
1059 ------------------------------------------------
1061 Like Element.getNext, but returns a collection of all the matched nextSiblings.
1065 Element Method: getFirst {#Element:getFirst}
1066 --------------------------------------------
1068 Gets the first element that matches the passed in expression.
1073 var firstElement = myElement.getFirst([match]);
1077 1. match - (*string*, optional): A full CSS selector to match the found element(s) with.
1081 * (*mixed*) The first found element or null if none found.
1085 Element Method: getLast {#Element:getLast}
1086 ------------------------------------------
1088 Gets the last element that matches the passed in expression.
1092 var lastElement = myElement.getLast([match]);
1096 1. match - (*string*, optional): A full CSS selector to match the found element(s) with.
1100 * (*mixed*) The last found element, or returns null if none found.
1104 Element Method: getParent {#Element:getParent}
1105 ----------------------------------------------
1107 Works as [Element:getPrevious][], but tries to find the parentNode.
1112 var parent = myElement.getParent([match]);
1116 1. match - (*string*, optional): A tag name to match the found element(s) with. A full CSS selector can be passed.
1120 * (*mixed*) The target Element's parent or null if no matching parent is found.
1124 Element Method: getParents {#Element:getParents}
1125 ------------------------------------------------
1127 Like [Element:getParent](#Element:getParent), but returns a collection of all the matched parentNodes up the tree.
1131 Element Method: getSiblings {#Element:getSiblings}
1132 --------------------------------------------------
1134 Like [Element:getAllPrevious][] but returns all Element's previous and next siblings (excluding text nodes). Returns as [Elements][].
1139 var siblings = myElement.getSiblings([match]);
1143 1. match - (*string*, optional): A tag name to match the found element(s) with. A full CSS selector can be passed.
1147 * (*array*) A [Elements](#Elements) array with all of the Element's siblings, except the text nodes.
1151 Element Method: getChildren {#Element:getChildren}
1152 --------------------------------------------------
1154 Returns all the Element's children (excluding text nodes). Returns as [Elements][].
1159 var children = myElement.getChildren([match]);
1163 1. match - (*string*, optional): A tag name to match the found element(s) with. A full CSS selector can be passed.
1167 * (*array*) A [Elements](#Elements) array with all of the Element's children, except the text nodes.
1171 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.
1173 Element Method: empty {#Element:empty}
1174 --------------------------------------
1176 Empties an Element of all its children.
1185 * (*element*) This Element.
1191 <div id="myElement">
1198 $('myElement').empty();
1200 ##### Resulting HTML
1202 <div id="myElement"></div>
1206 Element Method: destroy {#Element:destroy}
1207 ------------------------------------------
1209 Removes the Element and its children from the DOM and prepares them for garbage collection.
1213 myElement.destroy();
1221 Element Method: toQueryString {#Element:toQueryString}
1222 ------------------------------------------------------
1224 Reads the child inputs of the Element and generates a query string based on their values.
1229 var query = myElement.toQueryString();
1233 * (*string*) A string representation of a all the input Elements' names and values.
1239 <form id="myForm" action="submit.php">
1240 <input name="email" value="bob@bob.com" />
1241 <input name="zipCode" value="90210" />
1246 $('myForm').toQueryString(); // returns "email=bob@bob.com&zipCode=90210".
1249 Element Method: getSelected {#Element:getSelected}
1250 --------------------------------------------------
1252 Returns the selected options of a select element.
1257 var selected = mySelect.getSelected();
1261 * (*array*) An array of the selected elements.
1267 <select id="country-select" name="country">
1268 <option value="US">United States</option
1269 <option value ="IT">Italy</option>
1274 $('country-select').getSelected(); // returns whatever the user selected.
1278 This method returns an array, regardless of the multiple attribute of the select element.
1279 If the select is single, it will return an array with only one item.
1283 Element Method: getProperty {#Element:getProperty}
1284 --------------------------------------------------
1286 Returns a single element attribute.
1290 var myProp = myElement.getProperty(property);
1294 * property - (*string*) The property to be retrieved.
1298 * (*string*) A string containing the Element's requested property.
1304 <img id="myImage" src="mootools.png" title="MooTools, the compact JavaScript framework" alt="" />
1308 var imgProps = $('myImage').getProperty('src'); // returns: 'mootools.png'.
1312 Element Method: getProperties {#Element:getProperties}
1313 ------------------------------------------------------
1315 Gets multiple element attributes.
1319 var myProps = myElement.getProperties(properties);
1323 * properties - (*strings*) Any number of properties to be retrieved.
1327 * (*object*) An object containing all of the Element's requested properties.
1333 <img id="myImage" src="mootools.png" title="MooTools, the compact JavaScript framework" alt="" />
1337 var imgProps = $('myImage').getProperties('id', 'src', 'title', 'alt');
1338 // returns: { id: 'myImage', src: 'mootools.png', title: 'MooTools, the compact JavaScript framework', alt: '' }
1342 Element Method: setProperty {#Element:setProperty}
1343 --------------------------------------------------
1345 Sets an attribute or special property for this Element.
1350 1. property - (*string*) The property to assign the value passed in.
1351 2. value - (*mixed*) The value to assign to the property passed in.
1355 * (*element*) - This Element.
1361 <img id="myImage" />
1365 $('myImage').setProperty('src', 'mootools.png');
1367 ##### Resulting HTML
1369 <img id="myImage" src="mootools.png" />
1373 - Whenever using [Element:setProperty][] to set an attribute, pass in the lowercase, simplified form of the property. For example:
1374 - use 'for', not 'htmlFor',
1375 - use 'class', not 'className'
1376 - use 'frameborder', not 'frameBorder'
1380 Element Method: setProperties {#Element:setProperties}
1381 ------------------------------------------------------
1383 Sets numerous attributes for the Element.
1388 1. properties - (*object*) An object with key/value pairs.
1392 * (*element*) This Element.
1398 <img id="myImage" />
1402 $('myImage').setProperties({
1403 src: 'whatever.gif',
1404 alt: 'whatever dude'
1407 ##### Resulting HTML
1409 <img id="myImage" src="whatever.gif" alt="whatever dude" />
1413 Element Method: removeProperty {#Element:removeProperty}
1414 --------------------------------------------------------
1416 Removes an attribute from the Element.
1421 myElement.removeProperty(property);
1425 1. property - (*string*) The attribute to remove.
1429 * (*element*) This Element.
1435 <a id="myAnchor" href="#" onmousedown="alert('click');"></a>
1439 //Eww... inline JavaScript is bad! Let's get rid of it.
1440 $('myAnchor').removeProperty('onmousedown');
1442 ##### Resulting HTML
1444 <a id="myAnchor" href="#"></a>
1448 Element Method: removeProperties {#Element:removeProperties}
1449 ------------------------------------------------------------
1451 Removes numerous attributes from the Element.
1456 myElement.removeProperties(properties);
1460 1. properties - (*strings*) The attributes to remove, separated by comma.
1464 * (*element*) This Element.
1470 <a id="myAnchor" href="#" title="hello world"></a>
1474 $('myAnchor').removeProperties('id', 'href', 'title');
1476 ##### Resulting HTML
1481 Element Method: store {#Element:store}
1482 --------------------------------------
1484 Stores an item in the Elements Storage, linked to this Element.
1489 myElement.store(key, value);
1493 1. key - (*string*) The key you want to assign to the stored value.
1494 2. value - (*mixed*) Any value you want to store.
1498 * (*element*) This Element.
1502 $('element').store('someProperty', someValue);
1505 Element Method: retrieve {#Element:retrieve}
1506 --------------------------------------------
1508 Retrieves a value from the Elements storage.
1513 myElement.retrieve(key[, default]);
1517 1. key - (*string*) The key you want to retrieve from the storage.
1518 2. default - (*mixed*, optional) Default value to store and return if no value is stored.
1522 * (*mixed*) The value linked to the key.
1526 $('element').retrieve('someProperty'); // returns someValue (see example above)
1529 Element Method: eliminate {#Element:eliminate}
1530 --------------------------------------------
1532 Eliminates a key from the Elements storage.
1537 myElement.eliminate(key);
1541 1. key - (*string*) The key you want to eliminate from the storage.
1545 * (*mixed*) The element/window/document.
1549 $('element').eliminate('someProperty');
1555 Object: Element.Properties {#Element-Properties}
1556 ==============================================
1558 This Object contains the functions that respond to the first argument passed in [Element:get][], [Element:set][] and [Element:erase][].
1560 ### Adding a Custom Element Property
1562 Element.Properties.disabled = {
1565 return this.disabled;
1568 set: function(value){
1569 this.disabled = !!value;
1570 this.setAttribute('disabled', !!value);
1575 ### Using a Custom Element Property
1577 // gets the "disabled" property
1578 $(element).get('disabled');
1579 // sets the "disabled" property to true, along with the attribute
1580 $(element).set('disabled', true);
1583 ### Using an Object:
1585 Additionally, you can access these custom getters and setters using an object as the parameter for the [set](#Element:set) method.
1590 $(divElement).set({html: '<p>Hello <em>People</em>!</p>', style: 'background:red'});
1592 // for new Elements (works the same as set):
1593 new Element('input', {type: 'checkbox', checked: true, disabled: true});
1598 - Automatically returns the element for setters.
1599 - Since MooTools 1.3 this is a native JavaScript Object and not an instance of the deprecated Hash
1603 Element Property: html {#Element-Properties:html}
1604 -------------------------------------------------
1608 Sets the innerHTML of the Element.
1612 myElement.set('html', html);
1616 1. html - (*string*) The new content as HTML string.
1620 * (*element*) This Element.
1626 <div id="myElement"></div>
1630 $('myElement').set('html', '<div></div><p></p>');
1632 ##### Resulting HTML
1634 <div id="myElement">
1641 Returns the inner HTML of the Element.
1645 myElement.get('html');
1649 * (*text*) This Element's innerHTML.
1653 Element Property: text {#Element-Properties:text}
1654 -------------------------------------------------
1658 Sets the inner text of the Element.
1662 myElement.set('text', text);
1666 1. text - (*string*) The new text content for the Element.
1670 * (*element*) This Element.
1676 <div id="myElement"></div>
1680 $('myElement').set('text', 'some text');
1681 // the text of myElement is now 'some text'.
1683 ##### Resulting HTML
1685 <div id="myElement">some text</div>
1689 Gets the inner text of the Element.
1693 var myText = myElement.get('text');
1697 * (*string*) The text of the Element.
1703 <div id="myElement">my text</div>
1707 var myText = $('myElement').get('text'); // myText = 'my text'.
1711 Element Property: tag {#Element-Properties:tag}
1712 -----------------------------------------------
1716 Returns the tag name of the Element in lower case.
1720 var myTag = myElement.get('tag');
1724 * (*string*) The tag name in lower case.
1730 <img id="myImage" />
1734 var myTag = $('myImage').get('tag'); // myTag = 'img'
1738 Type: IFrame {#IFrame}
1739 ========================
1741 Custom Type to create and easily work with IFrames.
1745 IFrame Method: constructor {#IFrame:constructor}
1746 ------------------------------------------------
1748 Creates an IFrame HTML Element and extends its window and document with MooTools.
1753 var myIFrame = new IFrame([el][, props]);
1757 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).
1758 2. props - (*object*, optional) The properties to be applied to the new IFrame. Same as [Element:constructor](#Element:constructor) props argument.
1762 * (*element*) A new IFrame HTML Element.
1766 var myIFrame = new IFrame({
1768 src: 'http://mootools.net/',
1773 border: '1px solid #ccc'
1778 mouseenter: function(){
1779 alert('Welcome aboard.');
1782 mouseleave: function(){
1787 alert('The iframe has finished loading.');
1797 - If the IFrame already exists and has a different name than id, the name will be made the same as the id.
1798 - An IFrame's window and document will not be extended with MooTools methods.
1802 Type: Elements {#Elements}
1803 ============================
1805 The Elements class allows [Element][] methods to work on an [Elements][] array, as well as [Array][] Methods.
1809 Elements Method: constructor {#Elements:constructor}
1810 ----------------------------------------------------
1815 var myElements = new Elements(elements[, options]);
1819 1. elements - (*mixed*) An array of elements or an HTMLCollection Object.
1823 * (*array*) An array-like Elements collection with the [Element][], [Elements][] and [Array][] methods.
1827 #### Set Every Paragraph's Color to Red:
1829 $$('p').each(function(el){
1830 el.setStyle('color', 'red');
1833 // Because $$('myselector') also accepts Element methods, the below
1834 // example has the same effect as the one above.
1835 $$('p').setStyle('color', 'red');
1838 #### Create Elements From an Array:
1840 var myElements = new Elements(['myElementID', $('myElement'), 'myElementID2', document.getElementById('myElementID3')]);
1845 - In MooTools, every DOM function which returns a collection of nodes (such as [$$][]) returns the nodes as instances of Elements.
1846 - Because Elements is an array-like-object, it accepts all the [Array][] methods, while giving precedence to [Element][] and [Elements][] methods.
1847 - Every node of the Elements instance has all the [Element][] methods.
1851 - [$$][], [$][], [Element][], [Elements][], [Array][]
1855 Elements Method: filter {#Elements:filter}
1856 ----------------------------------------------
1858 Filters a collection of elements by a given tag name. This method will be able to filter by any selector.
1859 It also works like [Array:filter][], by filtering collection of elements with a function.
1864 var filteredElements = elements.filter(selector);
1868 1. selector - (*mixed*) A single CSS selector.
1872 * (*array*) A subset of this [Elements][] instance.
1875 Deprecated Functions {#Deprecated-Functions}
1876 ============================================
1878 Element Method: hasChild {#Deprecated-Functions:hasChild}
1879 ---------------------------------------------------------
1881 This method has been deprecated. Use [Element:contains][] instead.
1885 var myElement = document.id('element1');
1886 var myElement2 = document.id('element2');
1887 myElement !== myElement2 && myElement.contains(element2);
1889 // could be implemented as:
1890 Element.implement('hasChild', function(element){
1891 return this !== element && this.contains(element);
1896 [document:id]: #Window:document-id
1898 [$$]: #Window:dollars
1900 [Array]: /core/Types/Array
1901 [Array:filter]: /core/Types/Array#Array:filter
1904 [Elements]: #Elements
1905 [Element:set]: #Element:set
1906 [Element:get]: #Element:get
1907 [Element:erase]: #Element:erase
1908 [Element:setProperty]: #Element:setProperty
1909 [Element:getProperty]: #Element:getProperty
1910 [Element:removeProperty]: #Element:removeProperty
1911 [Element:getElement]: #Element:getElement
1912 [Element:getElements]: #Element:getElements
1913 [Element.Properties]: #Element-Properties
1914 [Element:getPrevious]: #Element:getPrevious
1915 [Element:getAllPrevious]: #Element:getAllPrevious
1916 [Element:contains]: #Element:contains
1918 [Element:addEvents]: /core/Element/Element.Event#Element:addEvents
1919 [Element:setStyles]: /core/Element/Element.Style#Element:setStyles
1921 [The Dollar Safe Mode]: http://mootools.net/blog/2009/06/22/the-dollar-safe-mode/
1923 [MDC Element:removeChild]: https://developer.mozilla.org/En/DOM/Node.removeChild
1924 [MDC Element:replaceChild]: https://developer.mozilla.org/En/DOM/Node.replaceChild