Abu Bakkar Siddique
Abu Bakkar Siddique

Reputation: 31

Remove clicked class by click/on click in Jquery?

Here is my code, all I want is to remove the class that I clicked.

I don't understand why it does not works, I tried both

$(document).ready(function(){
  $(".start").on("click", function(){       
    $(this).removeClass("start");
    return false;
  });
});

and

$(document).ready(function(){
  $(".start").click( function(){        
    $(this).removeClass("start");
    return false;
  });
});

index.php
in a while loop, I have

   <li><a href="#" class="start">Name</a> </li>

Upvotes: 0

Views: 51

Answers (4)

sottany
sottany

Reputation: 1098

add jquery library to your code visit jsfiddle http://jsfiddle.net/Jf8mp/15/jsfiddle

Upvotes: 1

Priyank
Priyank

Reputation: 3868

$(document).ready(function(){
     $(document).on('click','.start',function(){        
        $(this).removeClass("start");
        return false;
     });
  });

follow this also

Upvotes: 0

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

You may have forgotten to add reference of jquery...

This works fine here:

$(document).ready(function(){
  $(".start").on("click", function(){       
    $(this).removeClass("start");
  });
});
.start 
{
    color:black;
    background:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


   <li><a href="#" class="start">Name</a> </li>

Upvotes: 1

Naved Munshi
Naved Munshi

Reputation: 507

As the elements are created in while loop may be your class='start' element remains undetected. Try this..

      $(document).ready(function(){
         $(document).on('click','.start',function(){        
            $(this).removeClass("start");
            return false;
         });
      });

Upvotes: 1

Related Questions