Categories
JavaScript Answers

How to get the entire document HTML as a string with JavaScript?

Spread the love

To get the entire document HTML as a string with JavaScript, we use the innerHTML property.

For instance, we write

const markup = document.documentElement.innerHTML;
console.log(markup);

to get the htmlk element with document.documentElement.

Then we get the innerHTML property to the markup of its content as a string.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *