Dynamic styles are a key feature of DHTML. By using CSS, you can quickly change the appearance and formatting of elements in a document without adding or removing elements. This helps keep your 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.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Dynamic Styles</title> <style> ul {display:none;} </style> </head> <body> <h1>Welcome to Dynamic HTML</h1> <p><a href="#">Dynamic styles are a key feature of DHTML.</a></p> <ul> <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> showMe = function () { document.getElementsByTagName("h1")[0].style.color = "#990000"; document.getElementsByTagName("ul")[0].style.display = "block"; }; document.getElementsByTagName("a")[0].onclick = function (e) { e.preventDefault(); showMe(); }; </script> </body> </html>
No comments:
Post a Comment