-1

Please find my ul li here, This li is working for horizontal tab using a bootstrap tab. I'm trying to apply a class; when the 2nd and 3rd li have the class active, I want to apply a style class on the 1st li. simlarly for next 3 li and rest also. I've tried with jquery but didn't succeed.

<ul id="myTab" class="nav-tabs">
  <li class="side-menu-grp"><a href="#">Group One</a></li>
  <li><a href="#" data-toggle="tab">List One</a></li>
  <li><a href="#" data-toggle="tab">List Two</a></li>

  <li class="side-menu-grp"><a href="#">Group Two</a></li>
  <li><a href="#" data-toggle="tab">List One</a></li>
  <li><a href="#" data-toggle="tab">List Two</a></li>

  <li class="side-menu-grp"><a href="#">Group Three</a></li>
  <li><a href="#" data-toggle="tab">List One</a></li>
  <li><a href="#" data-toggle="tab">List Two</a></li>
</ul>
4

1 回答 1

0

我认为这就是你想要的:

$('.active').prev('.side-menu-grp').addClass('class');

它选择带有 class 的元素activeli如果您不重用该类,则为 s)并找到带有 class 的第一个先前的兄弟元素side-menu-grp并将您想要的类添加到它。

于 2013-02-12T15:32:45.160 回答