JQuery implements multiple button clicks to change color
- 2020-03-30 04:25:16
- OfStack
This small effect code is very simple, not to do more to explain, directly provided source code.
JQuery code:
<script type="text/javascript">
//Load event
$(function () {
var collection = $(".flag");
$.each(collection, function () {
$(this).addClass("start");
});
});
//Click on the event
function dj(dom) {
var collection = $(".flag");
$.each(collection, function () {
$(this).removeClass("end");
$(this).addClass("start");
});
$(dom).removeClass("start");
$(dom).addClass("end");
}
</script>
The Css code:
<style type="text/css">
.start
{
cursor:pointer;
color:Green;
}
.end
{
cursor:pointer;
color:Red;
}
</style>
Html code:
<span class="flag" onclick="dj(this)">LoveOne</span>
<span class="flag" onclick="dj(this)">LoveTwo</span>
<span class="flag" onclick="dj(this)">LoveThree</span>
<span class="flag" onclick="dj(this)">LoveFour</span>
Is it very simple, special effects are also very fun, friends can play freely, the scalability is still very strong, if you make other more fun, please let me know.