jquery - Remove the last cloned element -
I have a button to clone my form, and I want to add another button to delete a specific clone form. I am How can I do this?
I have used events JQuery Since your recently added element should be final, you must choose an appropriate selector You can use and get it: the closest and
remove , but it still does not work, it removes all the forms from me .
& lt; Input style = 'width: 60px;' Type = 'submit' square = 'clone' value = '+' / / gt; & Lt; Form name = 'form' id = 'form' method = 'POST' & gt; & Lt; Input style = 'width: 80px;' Type = 'submit' name = 'add_jo' value = 'submit all' / & gt; & Lt; div class = 'cform' & gt; & Lt; Td> & Lt; Input class = 'txtedit' placeholder = 'description' name = 'description []' /> gt; & Lt; / Td> & Lt; / Div & gt; & Lt; Input class = "txtedit" type = "submit" class = "remove" value = "cancel" /> & Lt; / Form & gt;
$ ('clone'). Click on (function (event) {event.preventDefault (); var tr = $ ('. Cform: first'); var newTr = tr.clone (); newTr.find (": input"). Val ('' ); // Find all input types (Input, Teddera), clear it newTr.appendTo (Tr.parent ());}); Click $ ("Remove") (function (e) {$ (this) .closest (".cform"). Remove (); e.preventDefault ();});
$ ("remove"). Click (function (e) {$ (". Cform: last-child"). Remove (); e.preventDefault ();});
Comments
Post a Comment