So I tried to make a Light Mode function. But to do that, I need to change the color of some elements, but I have assigned classes to them. Someone tell me how to use the document.getElementsByClassName() function to change the color of elements assigned that class?
I tried doing this (see second code snippet) but it only effects 1 Element. I have 2 of the same element with the same class on a page.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>title</title>
<style>
.myH1{
color:black;
</head>
<body>
<script>
function lightMode(){
document.body.style.background = "white";
document.getElementsByClassName("myH1").style.color="blue";
</script>
<h1 class="myH1">Header</h1>
<button onclick="lightMode()">☀</button>
</body>
</html>
function lightMode()
document.body.style.background="white";
const element = document.getElementsByClassName("myH1")
element.style.color="black";