title: Toggle the status of a checkbox in the checkbox hack with a hyperlink
body: <p>My colleague and I worked on a website that contains a FAQ page. After each question, there is an "Answer"(Antwoord) spoiler button. Clicking the button shows the answer below the current question, and above the next question. Clicking the button again hides the answer. This makes it easy to scroll through the list of all questions and find the question you could be interested in.</p>
  
  <p>Now the problem I face is that I want to link to for example the answer of question 5, from the answer of question 1.</p>
  
  <p>I could give the <code>&lt;div&gt;</code> that contains question 5 an <code>id=</code> property to link to that, but ideally, I want to show the answer straight away by making the hyperlink "click" the Answer button.</p>
  
  <p>It turns out that I will need to modify the checkbox hack in order for this to properly work, but I face the problem that I can't have both an Hyperlink and a Label on one piece of text.</p>
  
  <p><strong>Just to be clear:</strong> I'm looking for a solution using <strong>only</strong> HTML/CSS.</p>
  
  <hr>
  
  <p><strong>My original code with just a spoiler button</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.spoilerbutton {
    display: block;
    border: none;
    padding: 0px 0px;
    margin: 10px 0px;
    font-size: 150%;
    font-weight: bold;
    color: #000000;
    background-color: transparent;
    outline: 0;
  }
  
  .spoiler {
    overflow: hidden;
  }
  
  .spoiler&gt;div {
    -webkit-transition: all 0s ease;
    -moz-transition: margin 0s ease;
    -o-transition: all 0s ease;
    transition: margin 0s ease;
  }
  
  .spoilerbutton[value="Antwoord"]+.spoiler&gt;div {
    margin-top: -500%;
  }
  
  .spoilerbutton[value="Hide Antwoord"]+.spoiler {
    padding: 5px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;strong&gt;1. Question 1?&lt;/strong&gt; &lt;input class="spoilerbutton" onclick="this.value=this.value=='Antwoord'?'Verberg':'Antwoord';" type="button" value="Antwoord" /&gt;
  &lt;div class="spoiler"&gt;
    &lt;div&gt;
      &lt;ul&gt;
        &lt;li&gt;possible answer 1.&lt;/li&gt;
        &lt;li&gt;possible answer 2.&lt;/li&gt;
        &lt;li&gt;possible answer 3.&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <hr>
  
  <p><strong>Trying to implement solutions from:</strong> <a href="https://stackoverflow.com/questions/13630229/can-i-have-an-onclick-effect-in-css/32721572#32721572">Can I have an onclick effect in CSS?</a></p>
  
  <p>I get the following which doesn't work:
  <div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>#btnControll1 {
      display: none;
  }
  
  .spoilerbutton {
    display: block;
    border: none;
    padding: 0px 0px;
    margin: 10px 0px;
    font-size: 150%;
    font-weight: bold;
    color: #000000;
    background-color: transparent;
    outline: 0;
  }
  
  .spoiler {
    overflow: hidden;
  }
  
  .spoiler&gt;div {
    -webkit-transition: all 0s ease;
    -moz-transition: margin 0s ease;
    -o-transition: all 0s ease;
    transition: margin 0s ease;
  }
  
  #btnControl1:checked + label {
  margin-top; -500%
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;strong&gt;1. Question 1?&lt;/strong&gt; &lt;input type"chekbox" id="btnControl1" /&gt;
  &lt;label class="spoilerbutton" for="btnControl1"&gt;Antwoord&lt;/label&gt;
  &lt;div class="spoiler"&gt;
    &lt;div&gt;
      &lt;ul&gt;
        &lt;li&gt;possible answer 1.&lt;/li&gt;
        &lt;li&gt;possible answer 2.&lt;/li&gt;
        &lt;li&gt;possible answer 3.&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <hr>
  
  <p><strong>Using combinations of <code>&lt;label&gt;</code> and <code>&lt;a href&gt;</code></strong> (also not working)</p>
  
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.spoilerbutton {
  display: none;
  }
  .spoiler {
  overflow: hidden;
  height:2em;
  }
  .spoiler&gt;div {
  -webkit-transition: all 0s ease;
  -moz-transition: margin 0s ease;
  -o-transition: all 0s ease;
  transition: margin 0s ease;
  }
  .spoilerbutton+.spoiler&gt;div {
  margin-top: -500%;
  }
  .spoilerbutton+.spoiler&gt;label:before {
  content: 'Antwoord';
  font-size: 150%;
  font-weight: bold;
  color: #000000;
  }
  .spoilerbutton:checked+.spoiler&gt;label:before {
  content: 'Verberg';
  }
  .spoilerbutton:checked+.spoiler {
  height:auto;
  }
  .spoilerbutton:checked+.spoiler&gt;div {
  margin-top: 0;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;strong&gt;1. Question 1?&lt;/strong&gt; &lt;input type="checkbox" id="question1" value="checked" class="spoilerbutton"&gt;
  &lt;div class="spoiler"&gt;
  &lt;label for="question1"&gt;&lt;/label&gt;
  &lt;div&gt;
  &lt;ul&gt;
  &lt;li&gt;&lt;a href="#question5"&gt;&lt;label for="#answer5"&gt;Open 5. link first&lt;/label&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;label for="question5"&gt;&lt;a href="#answer5"&gt;Open 5. label first&lt;/a&gt;&lt;/label&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href="#answer5"&gt;Open 5. link only&lt;/a&gt;&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;strong&gt;2. Question 2?&lt;/strong&gt; &lt;input type="checkbox" id="question2" value="checked" class="spoilerbutton"&gt;
  &lt;div class="spoiler"&gt;
  &lt;label for="question2"&gt;&lt;/label&gt;
  &lt;div&gt;
  &lt;ul&gt;
  &lt;li&gt;possible answer 1.&lt;/li&gt;
  &lt;li&gt;possible answer 2.&lt;/li&gt;
  &lt;li&gt;possible answer 3.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;strong&gt;2. Question 3?&lt;/strong&gt; &lt;input type="checkbox" id="question3" value="checked" class="spoilerbutton"&gt;
  &lt;div class="spoiler"&gt;
  &lt;label for="question3"&gt;&lt;/label&gt;
  &lt;div&gt;
  &lt;ul&gt;
  &lt;li&gt;possible answer 1.&lt;/li&gt;
  &lt;li&gt;possible answer 2.&lt;/li&gt;
  &lt;li&gt;possible answer 3.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;strong&gt;2. Question 4?&lt;/strong&gt; &lt;input type="checkbox" id="question4" value="checked" class="spoilerbutton"&gt;
  &lt;div class="spoiler"&gt;
  &lt;label for="question4"&gt;&lt;/label&gt;
  &lt;div&gt;
  &lt;ul&gt;
  &lt;li&gt;possible answer 1.&lt;/li&gt;
  &lt;li&gt;possible answer 2.&lt;/li&gt;
  &lt;li&gt;possible answer 3.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;&lt;br&gt;
  &lt;br&gt;
  &lt;strong&gt;2. Question 5?&lt;/strong&gt; &lt;input type="checkbox" id="question5" value="checked" class="spoilerbutton"&gt;
  &lt;div class="spoiler" id="answer5"&gt;
  &lt;label for="question5"&gt;&lt;/label&gt;
  &lt;div&gt;
  &lt;ul&gt;
  &lt;li&gt;possible answer 1.&lt;/li&gt;
  &lt;li&gt;possible answer 2.&lt;/li&gt;
  &lt;li&gt;possible answer 3.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;/div&gt;
  &lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <hr>
  
  <p><strong>Also related</strong> <a href="https://stackoverflow.com/questions/54299689/how-to-toggle-a-checkbox-when-a-link-is-clicked">How to toggle a checkbox when a link is clicked?</a></p>
  
  <p>There are some great suggestions there, but I'm unable to adapt the <a href="https://stackoverflow.com/a/54299774/1481116">answer from</a> <a href="https://stackoverflow.com/users/2692688/tushar">Tushar</a> to my situation.</p>