1

I have stored HTML code in a variable and would like to add it into the body of my page.

Example code:

let htmlCode = <div class="anyclass"> \n' +
'      <div id="dummyId" name="someName"> \n' +
'            <br> \n' +
'            <br> \n' +
'            <br> \n' +
'            <br> \n' +
'            <br> \n' +
'            <br> \n' +                     
'      </div> \n' +
'  </div>';

Tried to insert it into the body of the page like this:

e.target.appendChild(htmlCode);

The failure message is:

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

What is the right way to add this code into the HTML structure? How do I transfer a variable into a node. Happy for some help. Thanks!

3

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.