Javascript Document Object Modeling provides the functionality to change the CSS style class name of the HTML div tag dynamically. Javascript change style class of Div tag function allows you to sets the new class name of the class attribute of Div tag dynamically. You can access the HTML div element using document.getElementById method to change the CSS classname property of the Div tag.
<head>
<title>Javascript Change Style Class of Div tag</title>
<style type="text/css">
</style>
<script language="javascript" type="text/javascript">
{
}
else
<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.
</html>
Above Javascript DOM example changes the class of HTML div tag onclick event of input button control of HTML. Javascript changeCssClass function takes the parameter as id of the div tag whose style class is to be changed. It performs the toggle function to change the class of Div tag and reverts back to the default class name when user clicks the button second time. You can embed the CSS style code inside the Head section of the HTML document using HTML style tag as shown in the above sample code.
Currently rated 4.0 by 1 people
Tags: javascript, dom, javascript change class, javascript change style, javascript dom, document object modeling, dhtml, dynamic html, javascript getelementbyid, javascript document object
10/11/2008 3:22:06 AM