I
I
Isaac Clark2015-10-28 18:18:29
JavaScript
Isaac Clark, 2015-10-28 18:18:29

How to convert HTML to string?

Hello.
I receive an element.

var container = document.getElementsByClassName('container')[0];

You need to cast this element to this type:
var container = document.getElementsByClassName('container')[0]; // '<div class="container">Something</div>'

How can this be done? That is, so that the function that will convert returns exactly the string in which there will be all the tags and text located in the container.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kravchenko, 2015-10-28
@Dark_Knight

var container = document.getElementsByClassName('container')[0];
console.log(container.outerHTML);

I
Ivanq, 2015-10-28
@Ivanq

container.outerHTML
Or container.innerHTML

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question