Get value of checkbox which is checked+jquery

Hi to all,

I have following checkboxes


<input type="checkbox" name="selector[]"
id="selector" value="id">#id<br>
<input type="checkbox" name="selector[]"
id="selector" value="class">.class<br>
<input type="checkbox" name="selector[]"
id="selector" value="element">element[@attribute]<br><br>
<input type="button" id="btnClick" name="btnClick" value="Click" />
 

how i get the values of checkboxes which is checked and put that values in javascript array when i click the button using jquery.

thanks in advance


$(function(){
  $('#btnClick').click(function(){
    var val = [];
    $(':checkbox:checked').each(function(i){
      val[i] = $(this).val();
    });
  });
});

thanks

Thank u so much man.you have really saved my life

Great answer, it helped me. Thank you very much