Javascript DOM style object provides the backgroundColor property of CSS styles to change the background color of HTML tags. You can use the Javascript function to change the background color style of any HTML element that has some width and height so that it could reflect the change in color of its background. Javascript style object consists of all the CSS properties that can be accessed using Javascript DOM method. You can access the HTML document Elements using Javascript document object’s methods such as document.getElementById or document.getElementByName. By passing the Id or Name of the HTML element to these Javascript methods you can use the style object along with CSS property name to change the background color of that particular HTML element or tag.
document.getElementById("HTML element id"). style. backgroundColor = "value";
Javascript style object name and CSS property name are case sensitive. Use the same pattern as it is used in the above syntax.
<head>
<title>Javascript Change Background Color Style</title>
<script language="javascript" type="text/javascript">
{
backColor = document.getElementById(objDivID).style.backgroundColor;
}
else
<div id="div1" style="background-color : #EEEEEE">
Javascript will change the background color of this Div tag dynamically.
</html>
Be the first to rate this post
Tags: javascript, dom, javascript change backgroundcolor, javascript change background color style, javascript style object, javascript document object, javascript getelementbyid, javascript change class, dhtml, dynamic html
10/11/2008 3:23:27 AM