Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using jquery to make class active

<div class="tabs">
    <ul id="tab" class="nav nav-tabs">
        <li class="active">
            <a href="#feed" data-toggle="tab">Feed</a>
        </li>
        <li>
            <a href="#dashboard" data-toggle="tab">Dashboard</a>
        </li>
    </ul>
</div>

When a user clicks the link below. i want to change the #dashboard li to active, and remove active from the #feed li. how do i do this?

<a href=".showfollowers" onclick='load_followers();' data-toggle="tab">See All</a>
like image 759
arboles Avatar asked Feb 21 '23 17:02

arboles


2 Answers

You better use unobtrusive javascript:

<a href=".showfollowers" id="foo" data-toggle="tab">See All</a>

Code:

$('#foo').click(function(){
        $('#dashboard').addClass('active');
        $('#feed').removeClass('active');
        load_followers();
        return false; // if needed.
    });

Though it can be done with inline scripts, inline code is deprecated.

like image 95
gdoron is supporting Monica Avatar answered Mar 04 '23 13:03

gdoron is supporting Monica


<div class="tabs">
              <ul id="tab" class="nav nav-tabs">
              <li class="active"><a href="#feed" data-toggle="tab">Feed</a></li>
              <li><a href="dashboard" data-toggle="tab">Dashboard</a></li>
              </ul>
          </div>

<a href="showfollowers" onclick='load_followers();' data-toggle="tab">See All</a>


$('.showfollowers').click(function(){
  $(#tab li).removeClass('active');
  $('#dashboard').parent().addClass('active');

})
like image 44
Jayantha Lal Sirisena Avatar answered Mar 04 '23 11:03

Jayantha Lal Sirisena