Class Dynamic Change true/ false

2019-03-04 08:20发布

What I have are multiple links in my nav bar but am having changing the ul class. There are just two of my buttons on this page I need to change the ul class form select to current and the current to select.

<div class="nav">
 <ul class=" current">
    <li>
      <a href="index.php">Home</a>
      <div class="select_sub">
        <ul class="sub">
          <li></li>
        </ul>
      </div>
    </li>
   </ul>

   <ul class=" select">
    <li>
      <a href="index.php?page=about_us" target="_self">About</a>
         <div class="select_sub">
            <ul class="sub">
               <li><a href="index.php?page=about_us">About Us</a></li>
               <li><a href="index.php?page=what_are_we">What are we</a></li>
            </ul>
         </div>                  
     </li>
   </ul>
</div>

2条回答
Luminary・发光体
2楼-- · 2019-03-04 08:29

You have lot of syntax errors .There is no need of using quotes for this and you missed ; at the end

replace

 $('this').removeClass('select')

with

 $(this).removeClass('select');

or use

$(this).removeClass('select'.)addClass("current");

$(document).ready(function() {
     $('.current').click(function(){
        $(this).removeClass('select'.)addClass("current");
      });
 });
查看更多
太酷不给撩
3楼-- · 2019-03-04 08:30
$(document).ready(function() {
   $('.select').click(function () {
       $('.current').removeClass('current').addClass('select');
   });
});
查看更多
登录 后发表回答