But for CSS work, where you want to merely react a bit to user behaviors,
make a few changes to the design of a page, or do a little animation, scripting
is quite powerful enough.
Modifying CSS Styles through Programming ...........................................
This next example shows you how to create your own effects — modifying
any style of any element (almostany style, anyway) in any way. Recall the
example from Chapter 15 that used a pseudo-class to change the color of a
link (an aelement) when the user hovered their mouse over the element?
Now you’ll see how to use a bit of trick scripting to make anykind of change
you want to a style — dynamically, while your page is displayed.
Changing styles ..................................................................................
Type this into Notepad or whatever text editor you like, or copy it from this
book’s Web site:
<html>
<head>
<script>
function changestyle(obj,sname,ch) {
var dom = document.getElementById(obj).style;
dom [sname] = ch;
}
</script>
<style>
#pfirst {
font-size: 8px;
width: 400px;
}
284 Part IV: Advanced CSS Techniques