To hide an HTML element when a radio button is not checked, you can add an event listener to the radio buttons and use JavaScript to check if the button is checked or not. If it is not checked, you can use CSS to set the display property of the element to "none".
Here's an example code snippet that hides an HTML element with the ID "myElement" when a radio button with the ID "myRadioButton" is unchecked:
471 chars16 lines
In this example, we first get references to the radio button and the HTML element using their IDs. We then add an event listener to the radio button that listens for changes. When the radio button changes, we check if it is checked or not using its checked
property. If it is checked, we set the display
property of the element to "block", which shows it. If it is not checked, we set the display
property to "none", which hides it.
Note that the radio button must have a unique ID and a name
attribute in order to work properly with other radio buttons in the same group.
gistlibby LogSnag