Remove elements onclick (including the remove button itself) with jQuery?

My suggestion would be like this. $(function () { var counter = 0; $('a'). Click(function () { var elems = ''+ '' + '' + '' + ''; $('#box').

Append(elems); $("#box"). Append(""); $("#box"). Append(""); counter++; }); $('.

Removebtn'). Live(function () { $(this).parent().remove(); }); }); simple demo.

Thank you very much – Opoe Dec 17 '10 at 9:44.

Suppose your remove button's id is #removebtn1234. Then $("#removebtn1234"). Click(function(){ $(this).remove(); }); should work But for easier manipulation on multiple items, I suggest you modify to following: $('a').

Click(function() { $('#box'). Append(''); $('#box'). Append(''); $('#box').

Append(''); $("#box"). Append(""); counter++; }); $(". Removebtn").

Click(function(){ var id = $(this). Data("id"); $("*data-id=" + id + "").remove(); }).

$("#removebtn1234"). Click(function(){ $(this).remove(); $("el1" + counter").remove(); $("el2" + counter").remove(); }); – Opoe Dec 17 '10 at 9:23 I modified the answer, you can still put id, but I simply draws the id out to be data field for easier manipulation. – xandy Dec 17 '10 at 9:26 Thank you very much xandy, the appendbutton doesn't append anything anymore with this code though – Opoe Dec 17 '10 at 9:33.

Here's a solution (which seems messier than it should, but I can't place my finger on it). $(function() { var counter = 0; $('a'). Click(function() { var checkBox = $(''), textBox = $(''), removeButton = $(''), containerDiv = $(""); removeButton.

Click(function(e) { e.preventDefault(); containerDiv.remove(); }); containerDiv . Append(checkBox) . Append(textBox) .

Append(removeButton); counter++; $("#box"). Append(containerDiv); }); }); In this solution, I make a variable of the jQuery reference. This way we can call things like checkBox.remove() and it will reference only that checkbox (without trying to work out the URL).

I have modified it a bit and removed the tags and wrapped everything in a . This way you can just remove the container div and all the elements will go. Example: http://jsfiddle.net/jonathon/YuyPB.

Thank you very helpful! :) – Opoe Dec 17 '10 at 9:43.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions