Class Dynamic Change true/ false

2019-03-04 08:16发布

问题:

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>

回答1:

$(document).ready(function() {
   $('.select').click(function () {
       $('.current').removeClass('current').addClass('select');
   });
});


回答2:

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");
      });
 });