javascript - jQuery remove cloned element on click -


I have a script that removes duplicate forms when clicked. But when you hit, I just want to remove the form that was cloned. I believe I need to use the $ this , but it's not sure how?

jQuery

  $ ("remove"). Click (function () {$ ('. Duplicate'). Remove ();});   

HTML

  & lt; Div class = "duplicate" & gt; & Lt; P & gt; Form Duplicate & lt; / P & gt; & Lt; A href = "#" class = "add" & gt; Add guest & lt; / A & gt; | & Lt; A href = "#" class = "remove" & gt; Remove & lt; / A & gt; & Lt; / Div & gt; & Lt; Div class = "duplicate" & gt; & Lt; P & gt; Form Duplicate & lt; / P & gt; & Lt; A href = "#" class = "add" & gt; Add guest & lt; / A & gt; | & Lt; A href = "#" class = "remove" & gt; Remove & lt; / A & gt; & Lt; / Div & gt;   

Here's a live preview.

Thank you!

Just use and do not forget about it:

  Click $ ("Remove") (function (e) {$ (this) .closest ("duplicate") .remove (); e.preventDefault ();});    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -