Transform div into string

1

How to make a div into a string? Here's the example of how I want it to be:

<div class="teste">oi</div>

on:

"<div class="teste">oi</div>"
    
asked by anonymous 11.05.2015 / 05:34

1 answer

2

Just use Element.outerHTML . Example:

var toString = document.getElementById('foo').outerHTML;
alert(toString);
<div id='foo' class='bar' data-baz='2015'>StackOverflow</div>
    
11.05.2015 / 06:12