What’s another more terse way to write the following. Basically it toggles the visibility of 2 button based on a condtion.
$("#myCheckBox").click(function() {
if (window.console && window.console.log)
console.log("billing only checked? " + this.checked);
if (this.checked) {
$("#btnNext").hide();
$("#btnFinish").show();
}
else {
$("#btnNext").show();
$("#btnFinish").hide();
}
});
Just looking for a more efficient way possibly?
You can use
.toggle, which accepts an argument indicating whether an element should be shown or hidden:If the visibility is correctly set up from the beginning, you don’t even have to pass an argument:
I agree with others regarding readability though.
.toggleby itself might be still understandable, but.toggle(!this.checked)can become more difficult to comprehend.