JavaScript

Tuesday April 8, 2025
updated: April 10, 2002

 
Home
Getting Started
Lesson 1
Lesson 2
Lesson 3
Lesson 4
Lesson 5
Lesson 6
Lesson 7
Lesson 8
Resources
Credits

 

 


   Lesson 7 Example 3: OnClick Change Background Color

Yellow Blue Purple White

Try clicking on the text in the boxes above.

On this page we are calling a function from a text link. We don't really want to go to a link so we put in a '#' in the HTML link tag as shown below.

<a href="#"OnClick="Yellow()">yellow"</a>

When the link is clicked the function is called. Remember the function is defined in the <HEAD> of our document.

<script language="JavaScript">
<!--// function Yellow() {document.bgColor="yellow"} //-->

WARNING: JAVA SCRIPT IS CASE SENSITIVE!

When written between <Script> tags the background color attribute MUST be written as: bgColor. Function names are also case sensitive in JavaScript.

 

back button
next button

© 2002 Tracy Johnson