Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore clicks for checkboxes?

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.

like image 558
temporary_user_name Avatar asked Jan 13 '23 20:01

temporary_user_name


2 Answers

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;
});
like image 189
Jeremy Blalock Avatar answered Jan 19 '23 11:01

Jeremy Blalock


Try something like this:

<input type="checkbox" onClick="this.checked=!this.checked" />
like image 39
John Lucabech Avatar answered Jan 19 '23 11:01

John Lucabech