I have a button and it takes some styles with first click. But I want the user to be able to reset to the original with second click on own button or any button in page.
How can I do this?
my codes
$("#checkButton").click(function() {
$("#checkButton").css("color", "yellow");
});
Answer
You can do it with CSS styling, but I've made a below snippet in case if you want to change color without make CSS.
Check current color, and then set the different one.
$("#checkButton").click(function() {
var color = $("#checkButton").css("color")
var yellow = "rgb(255, 255, 0)"
if (color !== yellow) {
$("#checkButton").css("color", yellow);
} else {
$("#checkButton").css("color", "");
}
});
No comments:
Post a Comment