Reputation: 3927
<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 );
});
Upvotes: 4
Views: 23324
Reputation: 37
$("#sample")
is used for id
$(".sample")
is used for class
Upvotes: 0
Reputation: 887
You used
$("#sample").append( newHTML );
but you defined sample to be a class (not an id) so you should use
$(".sample").append(newHTML);
To summarize, the "." is used for class and the "#" is used for id.
Upvotes: 1
Reputation:
sample is not id in your code its a class so change it to .sample instead of #sample.
Upvotes: 2
Reputation: 122026
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 );
Upvotes: 6