<div id = "content">123</div>
<button id = "b">сoхранить</button>
<script>
a = document.createElement("a")
a.setAttribute("href", "data:text/plain," + content.innerHTML)
a.setAttribute("download", "filename.txt")
b.onclick = function(){ a.click() }
</script>