jeudi 23 février 2017

Check dynamically generated checkboxes in table

I have a table with a checkboxes column, and I'm trying to do a 'checkall' checkbox. The problem is all checkboxes are generated dynamically. Table is something like this:

<table>
    <thead>
        <tr>
            <td>
                <input type="checkbox" id="checkall">
            </td>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td>
                <input type="checkbox" class="check">
            </td>
        </tr>
        <!-- More Checkboxes -->
    </tbody>
</table>

And this is the jquery code that I was using:

$('body').on('click','#checkall',function(){
    $('.check').prop('checked', this.checked);
});

The whole table content is generated dynamically.




Aucun commentaire:

Enregistrer un commentaire