You are here: Reference > JavaScript > client-side > style handling > properties > cssText (CSSRule, rule, style, ...)
cssText property (CSSRule, rule, style, ...)
Sets or retrieves the contents of a style declaration as a string.
The CSSValue.cssText, CSSRule.cssText and rule.cssText properties are read-only, all others are read/write.
Syntax:
You can find the related objects in the Supported by objects section below.
Possible values:
String that sets or returns the text value.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the cssText property for the style attribute:
|
||||
<head> <script type="text/javascript"> function GetStyle (elem) { alert (elem.style.cssText); } </script> </head> <body> <button onclick="GetStyle (this);" style="border:1px solid red;color:blue;">Get the complete style as a string!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the cssText property for style sheets and rules:
|
|||||
<head> <style id="myStyle" type="text/css"> body { background-color: red; } button { background-color: cyan; border: solid 1px blue; } </style> <script type="text/javascript"> function GetStyleSheetContent () { var styleTag = document.getElementById ("myStyle"); // the style sheet in the style tag var sheet = styleTag.sheet ? styleTag.sheet : styleTag.styleSheet; var message = ""; if ('cssText' in sheet) { // Internet Explorer message = sheet.cssText; } else { // Firefox, Opera, Google Chrome and Safari for (var i = 0; i < sheet.cssRules.length; i++) { message += sheet.cssRules[i].cssText; } } alert ("The contents of the imported style sheet:\n\n" + message); } </script> </head> <body> <button onclick="GetStyleSheetContent ()">Get the contents of the styleSheet!</button> </body> |
|||||
|
|||||
Did you find this example helpful?
|
Supported by objects:
CSSCharsetRule, CSSFontFaceRule, CSSImportRule, CSSMediaRule, CSSPageRule, CSSPrimitiveValue, CSSRule, CSSStyleRule, CSSValue, CSSValueList, rule, styleSheet
CSSStyleDeclaration, htmlElement.currentStyle, htmlElement.runtimeStyle, 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