Skip to content Skip to sidebar Skip to footer

$(this).checked Not Picking Up Checked Boxes

I have a function that is not picking up checkboxes correctly (if checked) with this function: function playerJson() { players = []; $('input[name=playerCheckList]').each(f

Solution 1:

That is referring to a jQuery object, which has no property 'checked' (The DOM would have that property though). You need to get the attribute value.

$(this).prop("checked");

Edit: I support qwertynl's answer because vanilla.js

Solution 2:

$(this).checked does not work because $(this) is a jQuery oject.

Just look at the checked attribute of the DOM object (this):

...
if (this.checked) {
    players.push(this.value);
}
...

Post a Comment for "$(this).checked Not Picking Up Checked Boxes"