I found out a crazy solution for dealing with this issue of checkbox not checked or checked
here is my algorithm...
create a global variable lets say var check_holder
check_holder has 3 states
- undefined state
- 0 state
- 1 state
If the checkbox is clicked,
$(document).on("click","#check",function(){
if(typeof(check_holder)=="undefined"){
//this means that it is the first time and the check is going to be checked
//do something
check_holder=1; //indicates that the is checked,it is in checked state
}
else if(check_holder==1){
//do something when the check is going to be unchecked
check_holder=0; //it means that it is not checked,it is in unchecked state
}
else if(check_holder==0){
//do something when the check is going to be checked
check_holder=1;//indicates that it is in a checked state
}
});
The code above can be used in many situation to find out if a checkbox has been checked or not checked. The concept behind it is to save the checkbox states in a variable, ie when it is on,off.
i Hope the logic can be used to solve your problem.
.click()
is invoked on the click event. Therefore I don't understand what you mean by "enable" and "disable". If the checkbox is checked you can invoke functiona()
. But you must write the reverse function to invoke when the checkbox is not checked. I'm confused..bind()
and.unbind()
events to another element based on the checkbox state. Is that what you're after?prop()
for what this question wanted to useattr()
for; theprop()
method had not been created back then. The answers aboutthis.checked
are probably still useful, however.