Reputation: 37078
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.
Upvotes: 4
Views: 4778
Reputation: 614
I am not sure if this is exactly what you want but this disables the checkbox using JQuery.
$('#checkboxId').attr('disabled', true);
For a non-grey out solution:
$("input:checkbox").click(function() { return false; });
Upvotes: -1
Reputation: 466
try this,
<input type="checkbox" onChange="return checkChange(this)" id="checkid"/>
function checkChange(obj)
{
obj.checked=false;
}
Upvotes: 0
Reputation: 5404
$('input[type=checkbox]').click(function(){return false;});
just return false on click event, working sample: http://jsfiddle.net/Sh8Zu/
Upvotes: 0
Reputation: 156
Try something like this:
<input type="checkbox" onClick="this.checked=!this.checked" />
Upvotes: 6
Reputation: 2619
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;
});
Upvotes: 8