title: Add 'active' class dynamically on foreach loop
body: <p>I want to add <code>active</code> class whenever I click on any 'li' of the table. 
  Statically i have successfully added 'active' class but now I want to add class dynamically using foreach loop.</p>
  
  <p><strong>Blade.php</strong></p>
  
  <pre><code>   @foreach($data as $key=&gt;$item)
          &lt;div class="roles-menu"&gt;
              &lt;ul class="nav" id="item_id" onclick="item()"&gt;
                              &lt;li id="active" onclick="makeactive()" class="{{ $loop-&gt;first ? 'active' : '' }}"&gt;
  &lt;a style="cursor: pointer" onclick="getID('{{ $item-&gt;id }}')"&gt;{{ $item-&gt;name }}&lt;/a&gt;&lt;/li&gt;
  
                  &lt;/li&gt;
              &lt;/ul&gt;
              &lt;input hidden id="input" value="{{ $item-&gt;id }}"&gt;
          &lt;/div&gt;
  
      @endforeach
  </code></pre>
  
  <p><strong>Script</strong></p>
  
  <pre><code>&lt;script&gt;
      function makeactive(){
          $('li a').click(function(e) {
              e.preventDefault();
              $(this).addClass('active');
          });
      }
  &lt;/script&gt;
  </code></pre>