How to ignore clicks for checkboxes?

checkbox, html, javascript, jquery

Solution

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;
});

Problem

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.

Original source