How Can I Highlight Text Background When Hovering Over Radio Buttons?

  • Thread starter jjiimmyy101
  • Start date
  • Tags
    Radio
In summary, the conversation is about a problem with highlighting the background of text when hovering over radio buttons. The solution provided is to add an id value to the labels and refer to them directly in the radio statements. This allows the background of the text to be highlighted when hovering over the corresponding radio button.
  • #1
jjiimmyy101
74
0
This is probably an easy solution, but I can't figure it out for the life of me. I have a bunch of radio buttons with corresponding text right next to it. What I want to happen is that when the mouse is moved over the radio button, I want the text background to get highlighted. As you can see from the code below, I only get the text background highlighted when the mouse is over the text or only the radio button is highlighted when the mouse is over the radio button. How can I fix this? Thanks. -jjiimmyy101


<input type="radio" name="Pizza" onMouseover="style.background='red'" onMouseout="style.background='white'" value="Large" id="Large">

<label for="Large" onMouseover="style.background='red'" onMouseout="style.background='white'">Large</label>

<input type="radio" name="Pizza1" onMouseover="style.background='red'" onMouseout="style.background='white'" value="Small" id="Small">

<label for="Small" onMouseover="style.background='red'" onMouseout="style.background='white'">Small</label>
 
Technology news on Phys.org
  • #2
Hi jjiimmyy101,

jjiimmyy101 said:
This is probably an easy solution, but I can't figure it out for the life of me. I have a bunch of radio buttons with corresponding text right next to it. What I want to happen is that when the mouse is moved over the radio button, I want the text background to get highlighted. As you can see from the code below, I only get the text background highlighted when the mouse is over the text or only the radio button is highlighted when the mouse is over the radio button. How can I fix this? Thanks. -jjiimmyy101


<input type="radio" name="Pizza" onMouseover="style.background='red'" onMouseout="style.background='white'" value="Large" id="Large">

<label for="Large" onMouseover="style.background='red'" onMouseout="style.background='white'">Large</label>

<input type="radio" name="Pizza1" onMouseover="style.background='red'" onMouseout="style.background='white'" value="Small" id="Small">

<label for="Small" onMouseover="style.background='red'" onMouseout="style.background='white'">Small</label>

If you add an id value to the labels, then you can refer directly to the label properties inside the radio statements (I've called the first label AAA and the second label BBB so you can see my additions easier):



<input type="radio" name="Pizza" onMouseover="AAA.style.background='red'" onMouseout="AAA.style.background='white'" value="Large" id="Large">

<label for="Large" onMouseover="style.background='red'" onMouseout="style.background='white'" id="AAA">Large</label>

<input type="radio" name="Pizza1" onMouseover="BBB.style.background='red'" onMouseout="BBB.style.background='white'" value="Small" id="Small">

<label for="Small" onMouseover="style.background='red'" onMouseout="style.background='white'" id="BBB">Small</label>
 
  • #3
Gee whiz. At least I knew the answer would be easy. Thank you so much :smile:
-jjiimmyy101
 
  • #4
jjiimmyy101 said:
Gee whiz. At least I knew the answer would be easy. Thank you so much :smile:
-jjiimmyy101

You're welcome!
 

1. What are radio buttons onMouseover?

Radio buttons onMouseover are interactive elements on a webpage that allow users to make a selection from a list of options by hovering their mouse over the button.

2. How do radio buttons onMouseover work?

When a user hovers their mouse over a radio button, the button will highlight or change color to indicate that it is selected. The user can then click on the button to make their selection.

3. Can radio buttons onMouseover be used for multiple selections?

No, radio buttons onMouseover are designed for single selections only. Only one button can be selected at a time.

4. How can I create radio buttons onMouseover on my webpage?

To create radio buttons onMouseover, you can use HTML <input type="radio" onmouseover="function()"> tags and add a JavaScript function to handle the hover behavior.

5. Are radio buttons onMouseover accessible for users with disabilities?

Yes, radio buttons onMouseover can be made accessible for users with disabilities by adding appropriate alt text and keyboard navigation options. It is important to follow accessibility guidelines when using any interactive elements on a webpage.

Similar threads

  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
Replies
2
Views
2K
  • Electrical Engineering
Replies
1
Views
2K
Replies
18
Views
6K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • Sci-Fi Writing and World Building
Replies
15
Views
3K
  • Astronomy and Astrophysics
Replies
1
Views
4K
  • General Discussion
Replies
1
Views
8K
Replies
16
Views
21K
Replies
22
Views
22K
Back
Top