I can not get checkboxes marked (one of the checkboxes is marked since its creation), what is my error?
function activar(){
var yourArray=[];
$("input:checkbox[name=vehicle]:checked").each(function(){
yourArray.push($(this).val());
});
console.log(yourArray);
}
activar();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
<input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
<input type="checkbox" name="vehicle" value="Car" checked> I have a car<br>
I try to tell me, every time I check or uncheck one of the checkboxes, which are the checkboxes that are marked.