Change color with Javascript : color « Style Basics « HTML / CSS






Change color with Javascript

  

<!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>Fix Colors</title>
 <script type="text/javascript" language="javascript">
<!--
function swapit(element) {
    var myElement = document.getElementById(element);
    myElement.style.color="red"
}
function revert(element) {
    var myElement = document.getElementById(element);
    myElement.style.color="black"
}
// -->
</script>
</head>
<body>
<h1 id="changeme">Changing Color</h1>
<p  onmouseover="swapit('changeme')" onmouseout="revert('changeme')">
This is a test. This is a test. This is a test. .</p>
</body>
</html>

   
  








Related examples in the same category

1.Colors
2.Hexadecimal Colors
3.background: lightblue
4.RGB Colors
5.RGB Colors with percentage
6.color: #333333
7.color: blue;
8.color:red
9.color:black; assigns the constant value black to the color property.
10.Use #fff for #ffffff
11.CSS Color Chart
12.Browser-Safe Color Chart
13.The Sixteen Basic Colors
14.User-Interface Color Keywords
15.rgb color
16.rgb color with percentage