I want to get an onClick event on found by id checkbox in div(should find it by id too).
My code is:
$('#myDivId').find('#myCheckboxId').change(function() {
if (this.checked) {
}
else{
}
});
but something goes wrong. I know that there should be one Id in page but is there any way to solve this problem?
Try this:
$('#myDivId>#myCheckboxId').change(function() {
if (this.checked) {
console.log('checked!');
}
else{
console.log('not checked');
}
});
Example is here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.