Вопрос

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...

Это было полезно?

Решение

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">
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top