jquery - Javascript Change Class Twice -


i have written following code that, when click on link whole style changed.

$(".buybuttons").click(function() {    $(".buybuttons").removeclass().addclass('buybuttonsclick');  });
.buybuttons {    background-color:#000000;    text-align:center;    padding:10px;  }    .buybuttonsclick {    background-color:#ff0000;    text-align:right;    padding:10px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  <a href="#" class="buybuttons">click change</a>

the question is, how can put reverse on it?!

i mean when click again, changes first style (buybuttons).

what toggleclass()?

$(".buybuttons").click(function() {    $(this).toggleclass('buybuttonsclick');  });
.buybuttons {    background-color:#000000;    text-align:center;    padding:10px;  }    .buybuttonsclick {    background-color:#ff0000;    text-align:right;    padding:10px;  }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  <a href="#" class="buybuttons">click change</a>


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -