Rob
Rob

Reputation: 6370

Targeting specific class with .find

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

Answers (2)

Rick Donohoe
Rick Donohoe

Reputation: 7271

var $checkboxes = $('input.correct:checkbox");

Upvotes: 0

radu florescu
radu florescu

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

Related Questions