JSFiddle - React, Tailwind, and code Playground

by Ganesh Salunkhe

HTML

<input type="checkbox" name="vehicle" />
<label>Car</label>
<input type="checkbox" name="vehicle" />
<label>Veh</label>

JavaScript

$("input:checked").each(function () {
$("input[type='checkbox']").change(function() {
    console.log($(this).next("label").text());
    alert($(this).next("label").text());
});
});

var selected = [];
$('input[type=checkbox]:checked').each(function() {
    selected.push($(this).attr('name'));
    alert(selected);
});