Removing rows dynamically with jQuery (currently can only add)

Hi - I can currently add a new row using javacript but what i need to be able to do is also remove the row.
below is the current code to add a row.

<script type='text/javascript'>
//<![CDATA[
 $(document).ready(function() {
  var currentItem = 1;
  $('#addnew').click(function(){
   currentItem++;
   $('#items').val(currentItem);
var strToAdd = '<tr><td width="10px"><input id="theDate'+currentItem+'" size="10" value="<? echo date(" d/m/Y "); ?>" name="theDate'+currentItem+'" type="text"></td><td><select id="Sport'+currentItem+'" name="Sport'+currentItem+'"><option>Horse Racing</option><option>Football</option><option>Greyhounds</option><option>NFL</option></select></td><td><input id="Pick'+currentItem+'" name="Pick'+currentItem+'" type="text"></td><td><select id="Bookie'+currentItem+'" name="Bookie'+currentItem+'"><option>Bet365</option><option>Betfred</option><option>BetVictor</option><option>Boylesports</option><option>Bwin</option><option>Centrebet</option><option>Coral</option><option>Ladbrokes</option><option>Paddy Power</option><option>Pinnacle Sports</option><option>SBOBET</option><option>Sky Bet</option><option>Stan James</option><option>unibet</option><option>William Hill</option></select></td><td><input id="Odds'+currentItem+'" name="Odds'+currentItem+'" size="3" type="text"></td><td><select id="BackorLay'+currentItem+'" name="BackorLay'+currentItem+'"><option>Back</option><option>Lay</option></select></td><td><input id="Stake'+currentItem+'" name="Stake'+currentItem+'" size="3" type="text">E/W<input name="EW'+currentItem+'" ID="EW'+currentItem+'" value="EW" type="checkbox" /></td><td><select id="Com'+currentItem+'" name="Com'+currentItem+'"><option>0</option><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option></select></td><td><select id="Outcome'+currentItem+'" name="Outcome'+currentItem+'"><option>Unknown</option><option>Win</option><option>Loss</option><option>P</option><option>E/W Win</option><option>Void</option></select></td><td><select id="PlaceDiv'+currentItem+'" name="PlaceDiv'+currentItem+'"><option>5</option><option>4</option></select></td></tr>';
   $('#data').append(strToAdd);
   
  });
 });
 
//]]>
</script>

Open in new window


how would i remove a row if row is more then 1?
runnerjp2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

leakim971PluritechnicianCommented:
what is the process to remove?
I don't see you delete button in the row
0
runnerjp2005Author Commented:
I have not added it yet - was awaiting guidance in case i was doing the "add" incorrectly
0
leakim971PluritechnicianCommented:
So in the row add a remove button :
<input type="button" class="remove-row" value="REMOVE" />

Open in new window


and add this code :
$("#data").on("click", ".remove-row", function(evt) {
     $(this).closest("tr").remove();
});

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

runnerjp2005Author Commented:
I added the code and it does not remove
0
runnerjp2005Author Commented:
0
leakim971PluritechnicianCommented:
the remove button is to ad on each line your add (line 8 in your code, original post/question)
0
leakim971PluritechnicianCommented:
and put the code inside document ready block, you should know why
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.