<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<table border="1" cellspacing="0" cellpadding="2" rules="all" width="200">
<tr>
<td style="background-color: blue;"> </td>
<td style="background-color: brown;"> </td>
</tr>
<tr>
<td style="background-color: crimson;"> </td>
<td style="background-color: orange"> </td>
</tr>
</table>
<script>
var tds = document.getElementsByTagName('td');
for(var i=0; i<tds.length; i++){
tds[i].onclick = function(){
document.body.style.backgroundColor = this.style.backgroundColor;
};
}
</script>
</body>
</html>