className property
Sets or retrieves the style class or classes that belong to the element.
With this property you can assign Cascading Style Sheets (CSS) declarations to an element.
CSS is useful for adding styling behaviors to an element.
For more information about Cascading Style Sheets, please see the page for style handling.
Syntax:
You can find the related objects in the Supported by objects section below.
This property is read/write.
HTML page for this property: class |
Possible values:
String that sets or retrieves a space-separated list of the related class names.
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the class attribute:
|
||||
<head> <style> .text {color: red;} </style> </head> <body> <p class="text" id="myP"> This text is red. </p> </body> |
||||
|
||||
Did you find this example helpful?
|
Example HTML code 2:
This example illustrates the use of the class attribute and the className property:
|
||||
<head> <style> .red { color: red; } .green { color: green; } </style> <script type="text/javascript"> function ChangeClass () { var parag = document.getElementById ("myP"); parag.className = (parag.className == "red")? "green" : "red"; } </script> </head> <body> <p class="red" id="myP"> The contents of the paragraph </p> <button onclick="ChangeClass ();">Change className!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
HTML elements:
a, abbr, acronym, address, applet, area, b, basefont, bdo, big, blink, blockquote, body, br, button, caption, center, cite, code, col, colgroup, 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, nobr, noframes, noscript, object, ol, optgroup, option, p, plaintext, pre, q, rt, ruby, s, samp, select, small, span, strike, strong, sub, sup, table, tbody, td, textarea, tfoot, th, thead, tr, tt, u, ul, var, xmp
Related pages:
External links:
User Contributed Comments