JSFiddle - React, Tailwind, and code Playground

by Neo Aptt

HTML

<div id='data'>
    <input id='1' type='checkbox' />
    <input id='2' type='checkbox' />
    <input id='3' type='checkbox' />
    <input id='4' type='checkbox' />
    <input id='5' type='checkbox' />
</div>
<div id='results'></div>
<button id='submit'>Submit</button>

JavaScript

/*sets variable to global so it can be accessed outside of function*/
var idList = [];
function run(){
    /*clears the original variable*/
    idList = [];
    $('#data').find('input[type="checkbox"]:checked').each(function () {
        idList.push(this.id);
    });
    /*prints after list is populated*/
    console.log(idList);
    $('#results').html(idList);
}
/*binds run function to click of submit*/
$('#submit').click(run);