var cell = $("<div></div>");
for (var j =0 ; j < items.paths.length ;j++){
cell.append(item.paths[j]);
}
$(`<tr><td style="white-space: normal;">
${cell}
</td></tr>`).appendTo('#mytable');
I made the dom object named cell
And I want to deploy the cell to html, however it shows only [object Object]
, where am I wrong?
2
Answers
If you are appending htmlStrings then do it all at once and then use
.join(', ')
to convert the array into a string (no iteration needed).Any object, when coerced into a string will output as
[object Object]
. Yourcell
variable is an object.Either build a string or don’t; you’re mixing the two.
You have a number of options:
cell
as a string rather than a dom object, egthough if doing that then use
.join()
cell
to a string, egnote: this will remove the outer
<div></div>
, so maybe${cell[0].outerHTML}