Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a checkbox unclickable *without* it being greyed out in the browser?

How do you create an HTML checkbox that is unclickable, but not greyed out? I used the disabled=disabled tag, but that makes it greyed out (in Chrome). Otherwise it works well. Working in jQuery and Rails...

Thanks.

like image 848
B Seven Avatar asked Jun 20 '11 13:06

B Seven


People also ask

How do I make a checkbox greyed out?

You can style checkbox label and readonly inputs with CSS, e.g.: input [readonly="readonly"] {} but the browser should make the checkbox should appear greyed out when set to readonly.

How do I make a non clickable checkbox?

How to make the checkbox un-changeable (answer: disable it) but still preserve the value of whether it is checked or not upon save (answer: use a hidden input type). Make sure to only add the hidden input if you have also disabled the checkbox.

How do I make a non editable checkbox in HTML?

The readonly attribute can be set to keep a user from changing the value until some other conditions have been met (like selecting a checkbox, etc.). Then, a JavaScript can remove the readonly value, and make the input field editable.

How do you make a checkbox Unclickable CSS?

You can put a transparent div on top of the checkbox to make it un-clickable by toggling a class on the parent object.


2 Answers

Usability concerns aside:

$("input:checkbox").click(function() { return false; });

For example: http://jsfiddle.net/nKwRj/

like image 71
Andrew Whitaker Avatar answered Sep 19 '22 07:09

Andrew Whitaker


Use jQuery.on with false as the callback:

$(":checkbox").on("click", false);

Fiddle

like image 40
Salman A Avatar answered Sep 23 '22 07:09

Salman A