I am facing an issue on my website where, on the index page, clicking a button changes the background color to black. However, this change is not reflected on other pages even though I have linked the JavaScript file to all HTML documents. How can I make it so that the background turns black on all pages when the button is clicked?
Here is what I've tried so far:
function updateBackgroundColor() {
document.getElementsByTagName("body")[0].style.cssText = "background: black;";
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
<style>
body {
background: white;
}
</style>
</head>
<body>
<button id="button" onclick="updateBackgroundColor()">Change to black</button>
</body>
</html>