[英]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 index.php
in a while loop, I have 在一段时间的循环中,我有
<li><a href="#" class="start">Name</a> </li>
You may have forgotten to add reference of jquery... 您可能已忘记添加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>
As the elements are created in while loop may be your class='start' element remains undetected. 由于元素是在while循环中创建的,因此您的class ='start'元素仍然未被检测到。 Try this.. 尝试这个..
$(document).ready(function(){
$(document).on('click','.start',function(){
$(this).removeClass("start");
return false;
});
});
将jquery库添加到您的代码中,请访问jsfiddle http://jsfiddle.net/Jf8mp/15/ jsfiddle
$(document).ready(function(){
$(document).on('click','.start',function(){
$(this).removeClass("start");
return false;
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.