Changing web page background color using JavaScript

This example will show you how to change the bgColor of a document using a click on a hypertext.

The demo page is available here, http://dhost.info/kerul/subjects/eg3_change_bgcolor.html


The Code :

<html>
<head>
<title>Changing bgColor on click of hypertext</title>
</head>
<body>
<p>This example will show you how to change the bgColor of a document using a
click on a hypertext... Have fun!</p>
<p><a href="javascript:" onclick="document.body.bgColor='red';">Red</a></p>
<p><a href="javascript:" onclick="document.body.bgColor='green';">Green</a></p>
<p><a href="javascript:" onclick="document.body.bgColor='blue';">Blue</a></p>
<p><a href="javascript:" onclick="document.body.bgColor='yellow';">Yellow</a></p>
<p><a href="javascript:" onclick="document.body.bgColor='white';">White</a></p>
<p><a href="javascript:" onclick="document.body.bgColor='black';">Black</a></p>
</body>
</html>


Popular Posts

WorldConferences.net