npm install htmltostring
<script src="https://cdn.jsdelivr.net/npm/htmltostring@1.0.6/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>