I want to activate this function,
$(document).keydown(function(e){
if (e.which == 65){
$('#test').click();
}
});
when this checkbook is checked.
<input type="checkbox" id="keyboard">
Sorry if this question is already exist.
I want to activate this function,
$(document).keydown(function(e){
if (e.which == 65){
$('#test').click();
}
});
when this checkbook is checked.
<input type="checkbox" id="keyboard">
Sorry if this question is already exist.
you can use this.
$("#keyboard").change(function() {
if ($(this).is(":checked")){
//your function goes here
}
});
Check is your checkbox checked inside that function. For example, one of way is to do it this way
$(document).keydown(function(e){
if (e.which == 65 && $('#keyboard:checked').length > 0){
$('#test').click();
}
});
This statement
$('#keyboard:checked').length > 0
checks whether there is more than 0 elements with id keyboard that are checked. You can also check using == 1. Other way is
$('#keyboard').prop('checked') == true
this is written in different manner, but works all the same.