Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable checkbox click via CSS

Tags:

html

css

checkbox

Is it possible to disable checkbox clicks via CSS. But keeping the functionality of the checkbox intact So we can set its values dynamically using Javascript. I wasn't able to find a proper solution.

pointer-events:none 

did not work

like image 891
Jacob Avatar asked Jan 22 '14 10:01

Jacob


People also ask

How do I make a checkbox not clickable 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.

How do I make a checkbox not clickable in HTML?

$(':checkbox[readonly]'). click(function(){ return false; });

How do I disable a checkbox?

The disabled property sets or returns whether a checkbox should be disabled, or not. A disabled element is unusable and un-clickable. Disabled elements are usually rendered in gray by default in browsers. This property reflects the HTML disabled attribute.

How do I GREY out a checkbox in CSS?

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. "checkbox itself should appear greyed out just by setting the readonly attribute" - Tried in IE8, FF12. 0, Chrome.


2 Answers

just the html solution will be like this.

<input type="checkbox" disabled="disabled" id="checkBox"/> 

if you wish to do this using javascript

document.getElementById("checkBox").disabled=true; 
like image 90
Green Wizard Avatar answered Sep 24 '22 23:09

Green Wizard


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

.container{    position:relative;    display:block;    }  .cover{    width:100%;    height:100%;    background:transparent;    position:absolute;    z-index:2;    top:0;    left:0;    display:none;    }    .container.disable-checkbox .cover{    display:block;  }
<div class="container">    <div class="cover"></div>    <input type="checkbox"/> "clickable"    </div>  <div class="container disable-checkbox">    <div class="cover"></div>    <input type="checkbox"/> "un-clickable"  </div>
like image 33
johanthuresson Avatar answered Sep 24 '22 23:09

johanthuresson