Exercise: Using clicks and array-like objects
Modify the code so that clicking on any table entry results in changes to the background colour using the colours in the array rainbow
and the classesAn attribute used to refer to a group of elements. in the CSS file. (The order of colours will be the same as the order in the array.)
Note:
Hints:
Use
getElementsByTagName
to obtain an array-like object of the table entry objects
Solution to the exercise
Here is a possible solution to the exercise.
Note:
Hints:
- undefined
1
2
window.onload = startFunction;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
<!DOCTYPE html>
<html lang="en">
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
td {
background-color: yellow;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX