I have a button, when the button is clicked, I want the variable ‘name’ to be added to my table
$('#myTable').click(function(id){
$('#Selection table').each(function (i) {
i = i+1;
$(this).prepend('<tr><td><a><p><b>1st name:</b>' + name + '" </a></tr></td>')
});
});
This code works! however, when the button is clicked a second time, I want the variable ‘name’ to be appended to the table (‘name’ is getting changed in the parent function). This code nearly works, however it adds the name variable to the table twice.
I would also like to find a way to label the second click with ‘2nd’ and then ‘3rd’ etc.
Thanks in advance for the help.
To keep track of the times #myTable is clicked you could do the following (I also fixed the invalid markup: