Search code examples
htmlcssradio-buttonstyleschecked

how to add checked class for id of an input-tag in a other tag <label> or <p> or <a>


I encountered a problem while doing the project.

why not run #MyId:checked~#show(style) for ID of a tag in <a> , <label> and <p>

is there a way to run css for it? without removing and moving the label tag , change the #test:checked~#show of this example to run properly.

#show {
  display: none;
  }
#test:checked~#show {
  display: block;
  }
<label>
 <input id="test" type="radio" value="0">click to show
</label>
<div id="show">
  hahahahahahha
</div>


Solution

  • Otherwise you can do that:

    #show {
      display: none;
      }
    #test:checked~#show {
      display: block;
      }
    <input id="test" type="checkbox"  >
    <label for="test">click to show</label>
    <div id="show">
      hahahahahahha
    </div>