Reputation: 6370
As a continuation of this question - Find checkboxes that are checked with a specific class
Is it possible to do the same with this jquery - I only want to target specifically the checkbox inputs with the class "correct"?
jQuery(function($) {
$(document).ready(function () {
$("input[type=checkbox]").click(function (e) {
if ($(e.currentTarget).closest("div.question").length > 0) {
toggleInputs($(e.currentTarget).closest("div.question")[0]);
}
});
});
function toggleInputs(questionElement) {
if ($(questionElement).data('max-answers') == undefined) {
return true;
} else {
maxAnswers = parseInt($(questionElement).data('max-answers'), 10);
if ($(questionElement).find(":checked").length >= maxAnswers) {
$(questionElement).find(":not(:checked)").attr("disabled", true);
} else {
$(questionElement).find("input[type=checkbox]").attr("disabled", false);
}
}
}
});
Upvotes: 1
Views: 65
Reputation: 4353
Try this:
$("input[type=checkbox].correct").click(function (e) {
if ($(e.currentTarget).closest("div.question").length > 0) {
toggleInputs($(e.currentTarget).closest("div.question")[0]);
}
});
Upvotes: 2