Selvamani Selvamani - 2 months ago 7
CSS Question

Add button dynamically using jquery

I am trying to add button dynamically, Here first button is only working but not other buttons, previously I was using

live
function, but jquery 1.9.1 removed that function. So what I do for to get work newly added buttons.

Here my html code

<div class="take">
<p>this is the para</p>
<button class="test">copy</button>
</div>


Here my juery code

$('.test').on('click', function() {
var a = $(this).parent();
new.clone().insertAfter(a);
})


Here the jsfiddle: fiddle

Answer

Passing true in clone will solve your problem - jsfiddle

$('.test').on('click', function() {
    var o = $(this).parent();
    o.clone(true).insertAfter(o);        
})

Note: new is a keyword in JavaScript so don't use it as a variable.