2

I have checkboxes using name="item[]", I can access them by using id, but the problem is they all have to have unique ids and class names. Is there any way I can access them by just the name property alone? That is the only thing they have in common. I have used this code, which works, but applies the same to the 2nd group of checkboxes. I have tried .attr('item[]'), but I am unsure if the array is messing things up. Ideas?

$( 'input:checkbox:checked' ).length;

2 Answers 2

3

you can use jquery selector:

$('input[name="item[]"]:checkbox:checked').length;

Also you can do what you want with your elements by for each loop:

$('input[name="item[]"]:checkbox:checked').each(function() {
    //do something
});

It will read all elements with this selector one-by-one and return in this attribute.

Sign up to request clarification or add additional context in comments.

Comments

2

Use attribute selector

$( 'input[name="item[]"]:checkbox:checked' ).length;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.