Reputation: 11735
I have a table in which I have many columns.
With my current code, I clone everything from the last row.
$("#tTable tbody tr:last").clone(true).insertBefore($("#tTable tbody tr:last")).show();
How can I modify this code so as to copy everything except the elements: lList, cSpan and its children?
<table id="tTable">
<tbody>
<tr>
<td>
<select id="lList" class="listClass">
<option value="0">(select here)</option>
<span class="cSpan"><input title="custom" class="custom-combobox-input ui-autocomplete-input" autocomplete="off">
<a class="comboboxButton ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only custom-combobox-toggle" tabindex="-1" role="button"><span class="ui-button-text"></span></a>
<div id="labelDiv"><label id="displayComboBoxText"></label>/div>
<input id="ID" name="ID" type="hidden" value="">
</td>
</tr>
</tbody>
</table>
Upvotes: 3
Views: 45
Reputation: 7437
This one worked for me: Fiddle
var tr = $("#tTable tbody tr:last");
var trCopy = tr.clone(true);
trCopy.find("td:first").remove();
trCopy.insertBefore(tr).show();
The .remove()
function (at least in jQuery 2.1.0) removes the selected element(s) as a side effect and returns the selection.
To empty the contents of the selected column without removing it, use html("")
:
trCopy.find("td:first").html("");
Upvotes: 0
Reputation: 9637
Use find selector to find td of first
then remove it
var row=$("#tTable tbody tr:last").clone(true).find("td:first").remove().end();
Upvotes: 2