poni
poni

Reputation: 27

How to add a string along with the appendChild?

How do I add a word in between two appendChild that are list items for example my code is the one below. This shows male 18, I want it to show male - age:18

x.appendChild (gender);
x.appendChild(age);
document.getElementById("list").appendChild(x);

Upvotes: 1

Views: 110

Answers (1)

Unmitigated
Unmitigated

Reputation: 89264

You can use append to add text nodes to an element.

x.appendChild (gender);
x.append(" - age:");
x.appendChild(age);

Upvotes: 2

Related Questions