vendredi 18 mars 2016

How to save dynamically added checkbox value in localStorage?

I want to save my checkbox value dynamically. When i check a specific one , all checkboxes are checked.Used target but did not work. Any ideas? JSFIDDLE

 var data = localStorage.getItem("checkbox");
    if (data) {
       $("input[name='checkbox-name']").attr("checked", "checked");
    }
    
  $(document).on('change', "input[name='checkbox-name']", function (e) {
     var target = $(e.target );
    if (target.is(":checked")) {
        localStorage.setItem("checkbox", 1);
    } else {
         localStorage.removeItem("checkbox");
    }
});



Aucun commentaire:

Enregistrer un commentaire