title: Jquery hide and show table rows in laravel dynamic table
body: <p>I've been trying to get showing and hiding certain table rows to work in a dynamically generated table. The table itself gets its data from a laravel collection.<br>
  The idea behind the table is that we want to have users to show labelgroups, these groups can have zero, one, or more labels with that group number. I display the labels under their appropriate group.</p>
  
  <p>The code is as follows:</p>
  
  <pre><code>&lt;table id="labeltable" class="table table-bordered"&gt;
    @foreach($labelgroups as $labelgroup)
      @foreach($labelgroup-&gt;all() as $groep)
        &lt;!-- Als de laatst ingevulde groep door de foreach loop verschillend is van de huidige groep, vul die dan in.
             Anders vul je deze en de rest van de headers niet in en wacht je tot er een nieuwe header is. --&gt;
        @if($lastgroup !== $groep-&gt;groep)
          &lt;thead&gt;
            &lt;tr&gt;
              &lt;td&gt;&lt;/td&gt;&lt;!-- Empty line --&gt;
            &lt;/tr&gt;
            &lt;tr style="background-color: #5cb85c"&gt;
              &lt;th&gt;{{ $groep-&gt;groep }}&lt;/th&gt;
              &lt;!-- Laatst ingevulde groep bepalen --&gt;
              {{ $lastgroup = $groep-&gt;groep }}
              @if($event-&gt;present()-&gt;nl)
                &lt;th&gt;{{Initialise::lang('lbl.algemeen.taal_1')}}&lt;/th&gt;
              @endif
              @if($event-&gt;present()-&gt;fr)
                &lt;th&gt;{{Initialise::lang('lbl.algemeen.taal_2')}}&lt;/th&gt;
              @endif
              @if($event-&gt;present()-&gt;en)
                &lt;th&gt;{{Initialise::lang('lbl.algemeen.taal_3')}}&lt;/th&gt;
              @endif
              @if($event-&gt;present()-&gt;de)
                &lt;th&gt;{{Initialise::lang('lbl.algemeen.taal_4')}}&lt;/th&gt;
              @endif
            &lt;/tr&gt;
          &lt;/thead&gt;
        @endif
      @endforeach
  
      @foreach($labelgroup-&gt;all() as $label)
        &lt;tbody&gt;
          &lt;tr class="{{ $groep-&gt;groep }}"&gt;
            &lt;td&gt;{{ $label-&gt;label }}&lt;/td&gt;
            @if($event-&gt;present()-&gt;nl)
              &lt;td&gt;{!!  Form::textarea('taal_1',$label-&gt;taal_1, array('id' =&gt; $label-&gt;id.'_1','rows' =&gt; 2, 'data-taal' =&gt; 'taal_1', 'data-url' =&gt; LinkHelper::route('label.update',$label-&gt;id),'class' =&gt; 'form-control', 'onchange' =&gt; 'initialise.update("'.LinkHelper::route('label.update',$label-&gt;id).'","taal_1",this.value);')) !!}&lt;/td&gt;
            @endif
            @if($event-&gt;present()-&gt;fr)
              &lt;td&gt;{!!  Form::textarea('taal_2',$label-&gt;taal_2, array('id' =&gt; $label-&gt;id.'_2','rows' =&gt; 2, 'data-taal' =&gt; 'taal_2', 'data-url' =&gt; LinkHelper::route('label.update',$label-&gt;id),'class' =&gt; 'form-control', 'onchange' =&gt; 'initialise.update("'.LinkHelper::route('label.update',$label-&gt;id).'","taal_2",this.value);')) !!}&lt;/td&gt;
            @endif
            @if($event-&gt;present()-&gt;en)
              &lt;td&gt;{!!  Form::textarea('taal_3',$label-&gt;taal_3, array('id' =&gt; $label-&gt;id.'_3','rows' =&gt; 2, 'data-taal' =&gt; 'taal_3','data-url' =&gt; LinkHelper::route('label.update',$label-&gt;id),'class' =&gt; 'form-control', 'onchange' =&gt; 'initialise.update("'.LinkHelper::route('label.update',$label-&gt;id).'","taal_3",this.value);')) !!}&lt;/td&gt;
            @endif
            @if($event-&gt;present()-&gt;de)
              &lt;td&gt;{!!  Form::textarea('taal_4',$label-&gt;taal_4, array('id' =&gt; $label-&gt;id.'_4','rows' =&gt; 2, 'data-taal' =&gt; 'taal_4','data-url' =&gt; LinkHelper::route('label.update',$label-&gt;id),'class' =&gt; 'form-control', 'onchange' =&gt; 'initialise.update("'.LinkHelper::route('label.update',$label-&gt;id).'","taal_4",this.value);')) !!}&lt;/td&gt;
            @endif
          &lt;/tr&gt;
        &lt;/tbody&gt;
      @endforeach
    @endforeach
  &lt;/table&gt;
  </code></pre>
  
  <p>The table code generates the following table; the image is a part of the table:</p>
  
  <p><a href="https://i.stack.imgur.com/1UMkE.png" rel="nofollow"><img src="https://i.stack.imgur.com/1UMkE.png" alt="Table example"></a></p>
  
  <p>Because the columns and rows are dynamically inserted I have no idea how to do a click event in which I can say that when I click on the header <code>&lt;th&gt;</code> element, I can hide the underlaying <code>&lt;td&gt;</code> elements (which represent labels that belong to the <code>&lt;th&gt;</code> group). Every <code>&lt;th&gt;</code> can have a different amount of rows corresponding with that 'group'. </p>
  
  <p>Could somebody give me some indicators as to how I'm supposed to do this?</p>