I am trying to change the background color of a <div>
when someone chooses a color from the drop-down menu.
It's a notes taking website and i want people can change color of the notes.
Here is the HTML code:
<select id="mySelect" class="clr-btn" style="text-align:center" onchange="change_color()">
<option id="red" value="Red">Red</option>
<option id="green" value="Green">Green</option>
<option id="blue" value="Blue">Blue</option>
</select>
Here is the Javascript:
function change_color() {
console.log("Change-Color");
let elm1 = document.getElementsByClassName("clr-btn");
let elm2 = elm1.options[elm1.selectedIndex].value;
let elm3 = document.getElementByClassName("card-body");
document.elm3.style.background = elm2;
}
The error is getting is that "Cannot read properties of un-defined" at elm2. I can't get what is undefined in elm2. Can anyone please help me out?