Sunday 27 March 2016

Write a JavaScript program to store different colors in an array and change the background color of the page using this array elements?

Code:


<!DOCTYPE html>
<html>
<body>
<center>
<script>
function myArray(n)
{
var backcolor=["#00f00","#ff0000","#0000ff","#cce"];
document.bgColor=backcolor[n];
}
</script>
<a href="#" onmouseover="myArray(1)">Red</a>
<a href="#" onmouseover="myArray(2)">Blue</a>
<a href="#" onmouseover="myArray(4)">Green</a>
<a href="#" onmouseover="myArray(3)">Ash</a>
<h1>Changing background color</h1>
</center>
</body>
</html>

Output:



No comments:

Post a Comment