Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery adding data to a div dynamically

Tags:

jquery

<div class="sample">
</div>

I would like to add data to the sample div on click. I am able to get the data to this function. verified with alert but it is not appending to the sample div.

$("#editsubmit").click(function(){

                  var val = $('[name=name111]').val();
                    var newHTML = '<input type="checkbox" name="'+val+'<br>';
                    $("#sample").append( newHTML );

           });  
like image 916
The Learner Avatar asked Jan 13 '23 12:01

The Learner


1 Answers

Class and id attributes mismatch.you have given as class and selecting as ID

 $(".sample").append( newHTML );

or change your div to

<div id="sample">  and then  $("#sample").append( newHTML );
like image 63
Suresh Atta Avatar answered Jan 21 '23 13:01

Suresh Atta