Pow
Pow

Reputation: 1367

Appending an object more than once using jQuery

I have tried to write a very simple code of jquery to append an element. Here is an example code -

<script type="text/javascript">
var v=$("strong");
  $(document).ready(function(){
            $("button").click(function(){

                    $(".c1").append($ (v) );

            });
        });
</script>

What happens here, the content of <div class="c1"> appears just once with multiple click. Instead of jQuery object, if I put html content then it appears as many as I click the button. I want to do the same thing with Object.

I started learning jQuery just today. So any sort of suggestion will be helpful.

Upvotes: 1

Views: 408

Answers (1)

Josiah Ruddell
Josiah Ruddell

Reputation: 29831

change this line:

$(".c1").append(v.clone());

If you want it to append the same node multiple times you need to either dynamically create that node, or clone the existing one.

Upvotes: 5

Related Questions