mardi 7 juillet 2015

Uncheck checkbox by id in jquery

Code :

$(function() {

$("input[type=checkbox]").on( "click", function() {
deptsSelected = '<div id = "selected_'+this.id+'">  '+ $("label[for='" + this.id + "']").text() + '<span id="delete">X</span></div>';
        $("#tabs").append(deptsSelected); 

});



    $(document).on("click", "#delete", function(e) { 
            id = $(this).parent().attr('id')
            e.preventDefault(); 
            $(this).parent().remove();  
            var checkid = $(id.slice(9));
            checkid.prop("checked", false);
  });

the code above should uncheck specific checkbox when the user click on the specific div the div is dynamically generated by jquery,so what I have done here is take the id of the new generated div and use slice function to take the id of the checkbox that I want to uncheck it. How can uncheck the box that I want using id ?




Aucun commentaire:

Enregistrer un commentaire