npm install htmltostring
<script src="https://cdn.jsdelivr.net/npm/[email protected]/htmlToString.min.js"></script>
//you don't have to import if you're using CDN
import htmlToString from 'htmltostring'
console.log(htmlToString('.container'))
// or
// const container = document.querySelector('.container')
// console.log(htmlToString(container))
<div class="container">
<h1>Hello World</h1>
</div>