Optimized Array.item: http://gist.github.com/87505
[mootools.git] / Docs / Element / Element.Style.md
blobc92e986daa619cb9f72eefff21d2aed8cb7e36ce
1 Native: Element {#Element}
2 ==========================
4 Custom Native to allow all of its methods to be used with any DOM element via the dollar function [$][].
8 Element Method: setStyle {#Element:setStyle}
9 --------------------------------------------
11 Sets a CSS property to the Element.
13 ### Syntax:
15         myElement.setStyle(property, value);
17 ### Arguments:
19 1. property - (*string*) The property to set.
20 2. value    - (*mixed*) The value to which to set it. Numeric values of properties requiring a unit will automatically be appended with 'px'.
22 ### Returns:
24 * (*element*) This element.
26 ### Example:
27         //Both lines have the same effect.
28         $('myElement').setStyle('width', '300px'); //The width is now 300px.
29         $('myElement').setStyle('width', 300); //The width is now 300px.
31 ### Notes:
33 - All number values will automatically be rounded to the nearest whole number.
37 Element Method: getStyle {#Element:getStyle}
38 --------------------------------------------
40 Returns the style of the Element given the property passed in.
42 ### Syntax:
44         var style = myElement.getStyle(property);
46 ### Arguments:
48 1. property - (*string*) The css style property you want to retrieve.
50 ### Returns:
52 * (*string*) The style value.
54 ### Examples:
56         $('myElement').getStyle('width'); //Returns "300px".
57         $('myElement').getStyle('width').toInt(); //Returns 300.
61 Element Method: setStyles {#Element:setStyles}
62 ----------------------------------------------
64 Applies a collection of styles to the Element.
66 ### Syntax:
68         myElement.setStyles(styles);
70 ### Arguments:
72 1. styles - (*object*) An object of property/value pairs for all the styles to apply.
74 ### Returns:
76 * (*element*) This element.
78 ### Example:
80         $('myElement').setStyles({
81                 border: '1px solid #000',
82                 width: 300,
83                 height: 400
84         });
86 ### See Also:
88 - [Element:getStyle][]
92 Element Method: getStyles {#Element:getStyles}
93 ----------------------------------------------
95 Returns an object of styles of the Element for each argument passed in.
97 ### Syntax:
99         var styles = myElement.getStyles(property[, property2[, property3[, ...]]]);
101 ### Arguments:
103 1. properties - (*strings*) Any number of style properties.
105 ### Returns:
107 * (*object*) An key/value object with the CSS styles as computed by the browser.
109 ### Examples:
111         $('myElement').getStyles('width', 'height', 'padding');
112         //returns {width: "10px", height: "10px", padding: "10px 0px 10px 0px"}
114 ### See Also:
116 - [Element:getStyle][]
120 [$]: /core/Element/Element/#dollar
121 [Function]: /core/Native/Function
122 [Element:getStyle]: #Element:getStyle