Learn Dynamic CSS with DHTML

Leave a Comment


The DHTML's object model allows us to change the style of the object using style attribute. This style is bassically known as a dynamic style of the object. For example : An user can enter some background color and that particular color can be set as a background color to our web page. The color name can be specified in a variable 'color_name' and it can be assigned as a background-color using attribute style as follows -
document.body.style.backgroundColor = color_name;

Here is an Example of DHTML Program
<html>
<head>
    <title>Dynamic Style Demo</title>
    <script type="text/javascript">
    function display(color_name){
     document.body.style.backgroundColor=color_name;
    }
    </script>
</head>
<body>
<form name="form1">
<b>Enter some color name here:</b><br />
<input type="text" name="text1" /><br /><br /><br />
<input type"button" name="button1" value="Click to change background color" onclick="display(form1.text1.value)" />
</form>
</body>
</html>

Output in Browser

DHTML Output in Browser

0 comments:

Post a Comment