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

JQuery

  $ ('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 ();});  

Since your recently added element should be final, you must choose an appropriate selector You can use and get it:

  $ ("remove"). Click (function (e) {$ (". Cform: last-child"). Remove (); e.preventDefault ();});    

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -