mercredi 12 juin 2019

Filter For table with checkboxes Vanilla JS / with working JQuery

I need help converting a JQuery in to the Vanilla JS.

I'm trying to filter an existing table using checkboxes (stocking as well). I've been using JQuery, and everything was working fine, but i'm not able to convert JQuery into Vanilla. Someone could help me out?

$(function () {
$('input[type="checkbox"]').change(function () {
    if ($('input[type="checkbox"]:checked').length > 0) {
        var vals = $('input[type="checkbox"]:checked').map(function () {
            return this.value;
        }).get();
        $('#senate-table tr')
            .hide()
            .filter(function () {
                return vals.indexOf($(this).find('td:nth-child(2)').text()) > -1;
            }).show();
    } else {
        $('#senate-table tr').show();
    }
});

});

I just need the corresponding Vanilla JS Code. I'm using 3 checkboxes to filter the content of the second column (td:nth-child(2)) of td.




Aucun commentaire:

Enregistrer un commentaire