3

How can I set a value to a node

var testVal = "some value"
var XML = document.createElement("div");
var Node = document.createElement("ROOT NODE");
var node1 = document.createElement("TESTING-ONE");

node1.appendChild( testVal );                                   
Node.appendChild(node1);
XML.appendChild(Node);

alert(XML.innerHTML);

1 Answer 1

3

Use createTextNode:

node1.appendChild(document.createTextNode(testVal));

Side note: element names cannot contain spaces, so the following is an error:

var Node = document.createElement("ROOT NODE");
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.