I have:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript index</title>
</head>
<body id="body">
<input name="colorButton" type="button" value="Change background color" />
<script>
"use strict";
function setBGColor() {
document.body.style.backgroundColor = "blue";
}
document.colorButton.onclick = setBGColor;
</script>
</body>
</html>
As you can see I am trying to change the background color of the body once the button is pressed. But I am getting the following error:
Uncaught TypeError: Cannot set property 'onclick' of undefined