4
<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 );

           });  
1
  • 1
    # is used for id but sample in your case is a class. So use dot(".sample") instead. Commented Apr 29, 2013 at 6:33

4 Answers 4

6

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 );
Sign up to request clarification or add additional context in comments.

Comments

2

sample is not id in your code its a class so change it to .sample instead of #sample.

Comments

1

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.

Comments

0
$("#sample") 

is used for id

$(".sample")

is used for class

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.