Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Dynamic HTML
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Dynamic styles== Dynamic styles are a key feature of DHTML. By using CSS, one can quickly change the appearance and formatting of elements in a document without adding or removing elements. This helps keep documents small and the scripts that manipulate the document fast. The object model provides programmatic access to styles. This means you can change inline styles on individual elements and change style rules using simple JavaScript programming. Inline styles are CSS style assignments that have been applied to an element using the style attribute. You can examine and set these styles by retrieving the style object for an individual element. For example, to highlight the text in a heading when the user moves the mouse pointer over it, you can use the style object to enlarge the font and change its color, as shown in the following simple example. <syntaxhighlight lang="html"> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Dynamic Styles</title> <style> ul { display: none; } </style> </head> <body> <h1 id="first-header">Welcome to Dynamic HTML</h1> <p><a id="clickable-link" href="#">Dynamic styles are a key feature of DHTML.</a></p> <ul id="unordered-list"> <li>Change the color, size, and typeface of text</li> <li>Show and hide text</li> <li>And much, much more</li> </ul> <p>We've only just begun!</p> <script> function showMe() { document.getElementById("first-header").style.color = "#990000"; document.getElementById("unordered-list").style.display = "block"; } document.getElementById("clickable-link").addEventListener("click", function (event) { event.preventDefault(); showMe(); }); </script> </body> </html> </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)