Reputation: 31
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
Reputation: 1098
add jquery library to your code
visit jsfiddle http://jsfiddle.net/Jf8mp/15/jsfiddle
Upvotes: 1
Reputation: 3868
$(document).ready(function(){
$(document).on('click','.start',function(){
$(this).removeClass("start");
return false;
});
});
Upvotes: 0
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
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