I have a checkbox that when you check that a div appears with a message, if the checkbox is unchecked, there is another div that appears with another message. I got this to work decently, but when you click the checkbox several times in a row, it gets confused and the messages are displayed incorrectly. Any ideas how to make this work better? (I am noOb in the jquery department, so any help is definitely appreciated). Thank you very much!
Check this!
HTML:
<input type="checkbox" name="chkWishList" id="chkWishList" />Checkbox Label<br /> <div class="message1"><span>Success<small></small></span></div> <div class="message2"><span>Removed<small></small></span></div>
JQuery
$(function() { $(".message1").css("display", "none"); $(".message2").css("display", "none"); $("#chkWishList").click(function() { if (this.checked) { $(".message1").fadeIn("fast").fadeOut(4000); $(".message2").hide(); } else { $(".message1").hide(); $(".message2").fadeIn("fast").fadeOut(4000); } }); });
source share