0

I want to make it so when the user hovers over the label of radio buttons for a series of colours, the label's background changes to that colour using javascript in a .js file. I appear to be having difficulty selecting the element, however. Nothing occurs when I hover over the labels, so I believe I have issues with selecting the labels. I am not to use jQuery for this problem.

let colourLabel = document.getElementsByName("label");
colourLabel.addEventListener("mouseover",function(event)
{
    event.target.style.color = "white";
    event.target.style.backgroundColor = colourLabel.textContent;
});
<fieldset>
  <legend>Colours</legend>
  <div>
   <input type="radio" name="colour" id="red" value="red" />
   <label for="red" name = "label">red</label>
  </div>
Nick
  • 138,499
  • 22
  • 57
  • 95

0 Answers0