I want to make a button that, when pressed, changes the background color of my page. Then, when you press it again, the page will go back to its original color. I don't understand how to make it go back to the original color again (using Toggle switch).
$(function () {
$("#button").click(function () {
$("p").css("background-color", "red");
});
});
Ideally you would use classes for this, which are easily toggled. For example:
If you must use direct style rules then one approach is to store the original value somewhere. Then in the click handler just compare the current value with that original and change it one way or the other. For example: