Class is a style
In JavaScript, if you want to modify the class attribute of an element, you must write it as className, because class is a reserved word of JavaScript.
<Script type = "text/javascript">
Function over (){
Var para = document. getElementById ("testPara"). className = "testOver ";
}
Function out (){
Var para = document. getElementById ("testPara"). className = "testNormal ";
}
</Script>
HTML code
In this example, only one paragraph is required, and the default class Attribute "testNormal" is set for it. The mouse over and over will trigger the above two JavaScript Functions respectively, this changes the class attribute of the paragraph.
<P id = "testPara" class = "testNormal" onmouseover = "over ()" onmouseout = "out ()">
I am an example section. If you move the mouse over me, you can change the attributes of my class to change the CSS rules of the application.
</P>
CSS
The CSS code sets two test styles.
. TestNormal {www.2cto.com
Border: 1px solid black;
}
. TestOver {
Background: #999999;
Border: 1px solid black;
Font-weight: bold;
Padding: 3em;
}
Author: Bychentufeiyang