Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type='text/css'>
#div1{
padding:7px 2px 2px 4px;background:#F8A0E0;
}
.div2{
padding:7px 2px 2px 4px;background:#F8A0E0;
}
#div1 a, #div1 h2{
color:#666666;
}
.newClass
{
background-color:#99CC99;
color:#000000;
font-family:Arial, Helvetica, sans-serif;
font-size:14px;
font-weight:bold;
border:2px solid #000;
width: 200px;
}
</style>
<script type="text/javascript">
function setColor(divId)
{
var bColor,fColor;
bColor = prompt('Please enter the new background color for the Div','');
fColor = prompt('Please enter the new foreground color for the Div','');
var divOb = document.getElementById(divId);
if(bColor != "")
divOb.style.backgroundColor = bColor;
if(fColor != "")
divOb.style.color = fColor;
}
function setClass(divId)
{
var divOb = document.getElementById(divId);
divOb.className = "newClass";
}
</script>
</head>
<body>
<div id="div1">DIV 1 Content Here</div><br>
<div id="div2" class="div2">DIV 2 Content Here</div><br>
<a href="#" onclick="setColor('div1');">change the color</a> <a href="#" onclick="setClass('div2');">setting class</a>
</body>
</html>
Try the above code

Originally Posted by
tech_support
Code:
document.getElementById(elementId).style.bgColor = color;
The bgColor property is now deprecated. Instead use
Bookmarks