2

I am creating a node:

var node = document.createElement("div");
node.setAttribute('class', 'my-class');
node.innerHTML = "Hello World";

Then I try to console.log the node in text format. If I use console.log(node) I do not get string, but node (I need string!). How can I get the whole node as string? Like this:

<div class="my-class">Hello World</div>

Kromel
  • 89
  • 4

1 Answers1

3

You can stringify a DOM node by using node.outerHTML.

hgs3
  • 525
  • 3
  • 6