0

I'm getting the following syntax error for my list of check boxes:

unrecognized expression: input:checked[name=match_list[]] 

HTML:

<label class="checkbox">
  <input type="checkbox" name="match_list[]" value="10">
   Item 10
</label>
<label class="checkbox">
  <input type="checkbox" name="match_list[]" value="20">
   Item 20
</label>

jQuery:

    var arr=[];

    $('input:checked[name=match_list[]]').each(function(){
        arr.push($(this).val());
    });

Any idea what the error is pointing to? The syntax looks fine to me...

3
  • 1
    Why are you nesting your input elements inside your label elements? Commented Nov 30, 2012 at 20:53
  • I'm using twitter bootstrap Commented Nov 30, 2012 at 20:56
  • @BrianDriscoll I'm sure you can use either label's for or nest the input inside a label.. they both work and are valid. Commented Nov 30, 2012 at 21:00

1 Answer 1

4

Use

$('input:checked[name="match_list[]"]').each(function(){

The quotes are only optional when it's easy to parse.

Regarding the input elements inside the label elements (a problem seen by Brian), you should use the for attribute :

<label class="checkbox" for=someid>Item 10</label>
<input type=someid "checkbox" name="match_list[]" value="10">
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.