Javascript to Change CSS Class of Div Tag

<title>Javascript Change CSS Class of Div tag</title>

<style type="text/css">

.redText,.blueText {
width: 200px;
font-family: Arial;

.redText {
color : red

.blueText {
color : blue


<script language="javascript" type="text/javascript">

function changeCssClass(objDivID)
document.getElementById(objDivID).className = 'blueText';
document.getElementById(objDivID).className = 'redText';



<div id="div1" class="redText">
By default text indside this HTML div tag is red.
Javascript function will change the CSS class<br />
of this Div tag and <br />
text color will change to blue dynamically.
<br />
<input type="button" value="click here" onclick="changeCssClass('div1')" />