Pawan
Pawan

Reputation: 32321

How to make a checkbox checked before adding it to the div

I have a HTML as shown below

 <form> 
<input type="checkbox" class="checkboxclas" name="checkbox-mini-0" id="' + random_number + '" data-mini="true" id_attr="' + random_number + '">
<label class="testtt" for="checkbox-mini-0">' + responseinner[i].name + '</label> 
</form> 

On click of a checkbox I am adding this above HTML to another div So before adding it to the another div , i need to make it checked .

I have tried the following .

$(document).on("click", ".checkboxclas", function(e) {

    if ($(this).is(':checked')) 
{
        var labelAttr = $(this).closest("form").find('label').text();
        var checkbox_val = $(this).find('.checkboxclas').prop('checked');
        var divdata = $("div#"+id_attr_val+".activateUiHTML").html();
        buildcart.append(divdata);
        $("#myordersdiv ul").append(dataa);
    }
});

This is my jsfiddle

could anybody please help me on this.

http://jsfiddle.net/e56TY/18/

Upvotes: 1

Views: 55

Answers (2)

Bhushan Kawadkar
Bhushan Kawadkar

Reputation: 28513

Try this :

$(document).on("click", ".checkboxclas", function(e) {

    var divdata = $("div.activateUiHTML").html();
    $("#ordersdiv").append(divdata).find(".checkboxclas:last").prop("checked",true);;

});

Demo

Upvotes: 1

NNR
NNR

Reputation: 303

Hope this will work for you :

Add one more line before appending.

    $(document).on("click", ".checkboxclas", function(e) {
        var divdata = $("div.activateUiHTML").html();
        $("#ordersdiv").append(divdata);

//Add this line in your code
           $("#ordersdiv").find(".checkboxclas").attr("checked","checked" );

    });

Upvotes: 1

Related Questions