Some ideas about style switched jquery

  Not long ago wrote some code, all button click on a button to switch the state, did not want to use addClass removeClass thoughtful to control the state of the control, then I think that is wrong.

<html>
<head>
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(function(){
$("ul li").click(function(e){
console.log(e.target);
   $(e.target).toggleClass("active")
});
})

</script>
<style type="text/css">
.normal{
 color:green;
}
.active{
color:red !important; 
}
</style>
</head>

<body>
<ul>
<li class='normal'>关于jquery addClass</li>
<li class='normal'>About removeClass jQuery </ Li> 
<class = Li 'Normal'> on jquery hasClass </ li>
<li class='normal'>关于jquery toggleClass</li>
</ul>
</body>
</html>

  

Guess you like

Origin www.cnblogs.com/AndyLin/p/11543430.html