How to place html tags inside javascript string?

I have this code right here:

"<!DOCTYPE html>\n"+

But the doctype, html, head and body tags dissapear when I console log it, but when viewing it as a P element, all of the tags go away and leave the hinput, cinput, jinput variables.

How do I make all of it stay when viewing as a P element?

>Solution :

innerHTML tries to parse the data as HTML. Hence the name.

If you want to treat it as plain text, use textContent instead.

Leave a Reply