jeudi 19 novembre 2015

jQuery Create array with atribute data and checked (true/false)

I Should create function, where with this markup

<ul id="#list">
  <li data-id="22"><input type="checkbox" data-id="22" checked></li>
  <li data-id="32"><input type="checkbox" data-id="32"></li>
  <li data-id="56"><input type="checkbox" data-id="56"></li>
  <li data-id="43"><input type="checkbox" data-id="43" checked></li>
</ul>

Return me data-id:true/false of checkbox checked

object: Array
22:true
32:false
56:false
43:true

I have this function

function () {
            return $('#list')
                .find('li')
                .map(function (i, el) {
                    return $(el).data('categoryid');
                })
                .get();
}

where return i:data-id (but data-id of li) How should I modify this code?




Aucun commentaire:

Enregistrer un commentaire