MAriiiyAM MAriiiyAM - 3 months ago 7
jQuery Question

Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node' error on append tr to a table

I have below code :

var counter = 3;
function AddAddressRow() {
var newRow = jQuery('<tr><td><div>' +
'<select class="dropdown-wrap k-rtl " id="ddlPrefix' +
counter +
'_1" style="width: 100px;">' +
'<option value="option1" selected="selected">Option 1</option>'+
'<option value="option2">Option 2</option>' +
'</select> <br /><br/></div></td><td><div>' +
'<select class="dropdown-wrap k-rtl " id="ddlPrefix' +
counter +
'_2" style="width: 100px;">' +
'<option value="option1" selected="selected">Option 1</option>' +
'<option value="option2">Option 2</option>' <
+'/select><br /></div></td><td><input style="width: 100px;"
id="txtAddress' + counter+'"/><br/><br/></td></tr>');
counter++;
$("table#AddressTable").append(newRow);
}


at on click of below button

<button onclick="AddAddressRow();">+</button>


I caught TypeError:


Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

Answer

The newRow is not returning a tr node. Check the fiddle here

Or try something like this:

var tr_ele = document.createElement('tr');
tr_ele.innerHTML = '>html here..<';
$("table#AddressTable").append(tr_ele);
Comments