mostrar un elemento html cuando maqrue un radio button y ocultarlo cuando no este marcado in javascript

You can achieve this by adding an event listener to the radio button and toggling the visibility property of the HTML element based on the checked status of the radio button. Here is an example:

<input type="radio" name="myRadio" id="myRadio"> Show element
<div id="myElement" style="display:none">This is the element to show/hide</div>
142 chars
3 lines
index.tsx
const myRadio = document.getElementById("myRadio");
const myElement = document.getElementById("myElement");

myRadio.addEventListener("change", () => {
  if (myRadio.checked) {
    myElement.style.display = "block";
  } else {
    myElement.style.display = "none";
  }
});
273 chars
11 lines

In the above code, we first grab references to the radio button and the HTML element we want to show/hide. We then add a change event listener to the radio button that checks if it is checked or not. If it is checked, we set the display property of the element to "block" to show it. If it is not checked, we set the display property to "none" to hide it.

gistlibby LogSnag