1

I am trying to append child via jQuery to the on of selected HTML element.

My code:

var table = $(this).parent();
console.log(table)
table.appendChild(table_row);

Console:

[table.table.unit-list, prevObject: jQuery.fn.init[1], context: tr] //log
... appendChild is not a function //error
Jax-p
  • 47
  • 1
  • 8

3 Answers3

7

Just use .append()

Description: Insert content, specified by the parameter, to the end of each element in the set of matched elements.

table.append(table_row);

Read about Difference between append and appendChild

Community
  • 1
  • 1
Amar Singh
  • 5,464
  • 2
  • 26
  • 55
2

You are trying to use pure JavaScript function appendChild with jQuery object.

To append your table use jQuery append table.append(table_row);

OR you can access to pure JavaScript object by getting very first element from jQuery table[0]. So it will be like table[0].appendChild(table_row);

Alex Pavlov
  • 150
  • 6
0

Since jquery $ function returns "Array" (actually it returns iterate-able object)

you can use

table[0].appendChild(tableRow)

if you want to use appendChild .

Ohad Sadan
  • 877
  • 6
  • 15