Search code examples
jquery

jQuery clone() function not working properly


Check out my jsFiddle http://jsfiddle.net/JV8eU/

I have clone the div tag using jQuery clone() function

When someone click on "Add new" then new clone of div tag will be added, and when someone click on "Remove" then that div tag will be removed.

There is one problem with that, the original div tag also contain remove button, so someone click on it that time original div tag also removed.

I don't want to show that Remove link at the execution of code, when someone click add then the Remove link appear with the clone of the div tag.


Solution

  • is this what you mean? http://jsfiddle.net/JV8eU/11/

    You can dynamically add the remove div before adding new content. like this way: obj.append('<div class="pull-left"><a href="#"onclick="removeDOM(this)">Remove</a></div>');