jQuery checkbox change and click event

Tested in JSFiddle and does what you’re asking for.This approach has the added benefit of firing when a label associated with a checkbox is clicked. Updated Answer: $(document).ready(function() { //set initial state. $(‘#textbox1’).val(this.checked); $(‘#checkbox1’).change(function() { if(this.checked) { var returnVal = confirm(“Are you sure?”); $(this).prop(“checked”, returnVal); } $(‘#textbox1’).val(this.checked); }); }); Original Answer: $(document).ready(function() { //set initial … Read more

event.preventDefault() vs. return false

return false from within a jQuery event handler is effectively the same as calling both e.preventDefault and e.stopPropagation on the passed jQuery.Event object. e.preventDefault() will prevent the default event from occuring, e.stopPropagation() will prevent the event from bubbling up and return false will do both. Note that this behaviour differs from normal (non-jQuery) event handlers, … Read more