samedi 6 mai 2017

jQuery, check if checkbox is checked with the same class

I'm trying to get values of a table with jQuery. Every table row has a checkbox at the begining. How can I copy data of each row, but only if it's checked. All checkboxes and rows has the same class. Now I'm using this code:

var table = $("table");
    var allRows = [];
    table.find('tr').each(function (i, el) {
        if($('input:checkbox:checked').length > 0){
            var $tds = $(this).find('td'),
            name = $tds.eq(2).text(),
            surname = $tds.eq(4).text();
            allRows.push(surname+";"+name+";"+"\n");
        }
    });
    allRows = allRows.join("");

But it's getting all the lines. How can I do this only for lines which are checked?




Aucun commentaire:

Enregistrer un commentaire