I need to save content of div using pure javascript. I just edited one fiddle but I can't make it works :(
jsfiddle
<div id="content">
<h1>Hello world</h1>
<i>Hi everybody</i>
Download
function download(){
var a = document.body.appendChild(
document.createElement("a")
);
a.download = "export.html";
a.href = "data:text/html," + document.getElementById("content");
}
Close, you need innerHTML & trigger the click too:
function download(){
var a = document.body.appendChild(
document.createElement("a")
);
a.download = "export.html";
a.href = "data:text/html," + document.getElementById("content").innerHTML; // Grab the HTML
a.click(); // Trigger a click on the element
}
Working Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With