Home › Forums › JavaScript › JS Add/Remove Row in Table › Reply To: JS Add/Remove Row in Table
August 27, 2013 at 7:24 am
#148227
Participant
So, I’m still kind of a noob on JS, but you may want to use jQuery here.
First things first: you really shouldn’t use tables for anything other than tabular data, I would try using divs and whatnot. But, since you may have your own reasons, let’s start.
You’ll need is get the code for that row in a string, and the data you want to change in variables. Something like:
var formIndex = 1;
var newRow = '<tr><td>Some content<tr><td>'
newRow += '<td><textarea id="'+formIndex+'"></textarea>';
Then, you can use jQuery’s append $('.emptyDiv').append(newRow)
to include that new code, not forgetting to increase that index formIndex+= 1