Turn div into string

Asked

Viewed 139 times

1

How to turn a div into a string? Follow the example of how I wish it to look:

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

in:

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

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>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.