There is a table with a link that adds a new row when clicked:
<table>
<thead>
<tr>
<th scope="col">col1</th>
<th scope="col">col2</th>
<th scope="col">col3</th>
</tr>
</thead>
<tbody>
<tr>
<td><input name="col1" id="col1"></td>
<td><input name="col2" id="col2"></td>
<td>
<select name="col3" id="col3">
<option value="">Please select</option>
<option value="1">select1</option>
<option value="2">select1</option>
<option value="3">select1</option>
</select>
</td>
</tr>
</tbody>
</table>
<a href="#" id="addLink">+</a>
when the link is clicked, I want to add a new row but without the 3rd column to the end of the table. so I used JQuery to do it:
$(document).ready(function(){
$('#addLink').click(function(){
addTableRow($("table"));
return false;
}); // end click
function addTableRow(table)
{
// get the first row in the table
var $tr = $(table).find("tbody tr:first").html();
$($tr).remove('td:last'); // remove the last column
$('tbody').append("<tr>");
$(table).find('tbody tr:last').append($tr);
};
}); // end ready
however, this part is not removing the 3rd column:
$($tr).remove('td:last'); // remove the last column
is there any way to append a new row with just the first 2 column?
Thanks in advance 🙂
is this what you’re looking for?
i changed a few other things as well, you’ll get the idea.
http://jsfiddle.net/QTuzM/