You are here: Reference > JavaScript > client-side > style handling > methods > item (currentStyle, style, ...)
item method (currentStyle, style, ...)
9 | ||||
Returns the name of the property that is located at the specified position in the current style object.
Note: The item method is supported in Internet Explorer from version 9.
The order of properties is browser dependent.
This method is useful if you want to iterate over the properties of a style object.
The number of properties can be retrieved with the length property.
The name of a style property can be used for the getPropertyValue, removeProperty and setProperty methods.Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. Zero-based integer that specifies the index of the style property. |
Return value:
String. The name of the style property.
Example HTML code 1:
This example illustrates the use of the item method:
|
||||
<head> <script type="text/javascript"> function IterateStyles (button) { for (i = 0; i < button.style.length; i++) { var propName = button.style.item (i); var value = button.style.getPropertyValue (propName); alert (propName + " = " + value); } } </script> </head> <body> <button onclick="IterateStyles (this)" style="margin:10px;">Iterate styles</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.style
HTML elements:
a, abbr, acronym, address, applet, area, b, base, basefont, bdo, bgsound, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, comment, dd, del, dfn, dir, div, dl, dt, em, embed, fieldset, font, form, frame, frameset, h1, h2, h3, h4, h5, h6, head, hr, html, i, iframe, img, input:button, input:checkbox, input:file, input:hidden, input:image, input:password, input:radio, input:range, input:reset, input:search, input:submit, input:text, ins, isindex, kbd, keygen, label, legend, li, link, listing, map, marquee, menu, meta, nobr, noframes, noscript, object, ol, optgroup, option, p, param, plaintext, pre, q, rt, ruby, s, samp, script, select, small, span, strike, strong, style, sub, sup, table, tbody, td, textarea, tfoot, th, thead, title, tr, tt, u, ul, var, wbr, xml, xmp
Related pages:
External links:
User Contributed Comments