I have a dropdown menu that contains checkboxes, and more than one can be checked at once. When a checkbox is selected, it's label's class is set to "checked" and then removed when it is deselected.
Before checkbox is selected:
<label><input type="checkbox" name="gainlosstypes[]" value="Losses" class="upperFilter">Losses</label>
After checkbox is selected:
<label class="checked"><input type="checkbox" name="gainlosstypes[]" value="Losses" class="upperFilte">Losses</label>
When it is selected the label element has .toggleClass('checked')
called on it.
I need to be able to detect which label's have their class set to "checked" so that I can filter data based on those fields.
If $(this)
is the label element, when I try $(this).hasClass('checked')
it throws an error. That's the only way I know to try. Is there some other way to tell if a specific label element has a specific class?
Edit:
I get these errors when trying to check for the attribute. It also happens when I use hasClass:
> $(".multiSelectOptions :checkbox")[1].attr('checked')
TypeError: Object #<HTMLInputElement> has no method 'attr'
> $(".multiSelectOptions :checkbox").parent('label')[1].attr('checked')
TypeError: Object #<HTMLLabelElement> has no method 'attr'