I am quite new to HTML/CSS/JavaScript and I was wondering how I could change the background colour, with a combination of JavaScript? I have 3 buttons (red, green and blue), and whenever the user presses on one of the three buttons, the background should change accordingly.
Currently, only the 'red' button works. The background doesn't change for the blue and green buttons.
Thanks in advance!
<!DOCTYPE html>
<html lang="en">
<head>
<title>My Webpage</title>
</head>
<body>
<button id = "red" value = "red">R</button>
<button id = "green" value = "green">G</button>
<button id = "blue" value = "blue">B</button>
<script>
document.querySelector('button').onclick = function() {
document.querySelector('body').style.backgroundColor = this.value;
}
</script>
</body>
</html>