jQuery: selecting checked checkbox

The name of the field isn’t foo, it is foo[]. You could use the attributeStartsWith selector:

$("input[name^='foo']:checked:enabled",'#myform');

Ideally, you’d be able to do this:

$("input[name="foo[]"]:checked:enabled",'#myform');

But as this answer explains, jQuery uses this to parse the value part of the attr=value condition:

(['"]*)(.*?)\3|)\s*\]

\3 being the group containing the opening quotes, which weirdly are allowed to be multiple opening quotes, or no opening quotes at all. The .*? then can parse any character, including quotes until it hits the first ‘]’ character, ending the match. There is no provision for backslash-escaping CSS special characters, so you can’t match an arbitrary string value in jQuery.

In other words, as soon as jQuery hits the first ] it thinks the value is over. So you are stuck with startsWith or using pure DOM elements, as that answer also explains.

SUPER DUPER IMPORTANT EDIT:
This bug is fixed, apparently. You should be able to use the code I described as “ideal”, above.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)