User283571144 posted
Hi BoutrosDouaihy,
As far as I know, if your page has refreshed the color you have set in the jQuery will also disappear.
So if you want to maintain the css style, you should store the css style in somewhere.
When page loading completely, you should set the css style again.
I suggest you could consider using cookie.
You could store the button background color in cookie.
More details, you could refer to below codes:
<script src="Scripts/jquery-1.10.2.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js"></script>
<script>
$(function () {
$("#Button1").css("background-color", Cookies.get('color'));
$("#Button1").click(function () {
$("#Button1").css("background-color", "red");
Cookies.set('color', 'red');
Cookies.remove('name');
});
$("#Button2").click(function () {
$("#Button1").css("background-color", "");
Cookies.remove('color');
});
});
</script>
Notice:Since cookie has the time to expire, you should have another function to delete the cookie.
Best Regards,
Brando