I need to attach a function to a checkbox so that clicking it does nothing. How is this possible? I don't want it to be greyed out, I just want to stop it from being togglable.
If you want it to be toggleable, just attach an event listener as follows:
$('#checkboxId').on('click', function(e) {
e.preventDefault();
e.stopPropagation();
});
Note: This is the same effect as returning false
:
$('#checkboxId').on('click', function(e) {
return false;
});
Try something like this:
<input type="checkbox" onClick="this.checked=!this.checked" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With