JavaScript how to convert object document.createElement to string

javascript

Solution

use outerHTML

var h1 = document.createElement("h1")
h1.innerHTML = "hello world"
alert(h1.outerHTML)

Demo: Fiddle

Problem

it is impossible to get a string of `createElement` that you would assign to a variable ``` var h1 = document.createElement("h1") h1.innerHTML = "hello world" alert(h1) return "[object HTMLHeadingElement]" ``` when i use `appendChild` is work but i must use alert or other method

Original source

Related problems