Search code examples
jqueryfilehtmlclone

Copy a div to a text file


needing some help here with jquery. I have a div i want to copy to a text file. This div has a class, and inside this div, there is some other divs and some other elements, but no one with the same .class as the main div. I'm not sure if i am able to use .clone() So what i need is something like this:

$('.myClass').misteriousCopyFunction('toTextFile');
//as i said, i'm not sure about this.

and my html looks like this

...
<div class="myClass">
  *lots of stuff*
  *lots of stuff*
  *lots of stuff*
</div>
...

it's just a little piece of the Html code to output to a new file in the current folder. Sorry if i said something stupid =P


Solution

  • You can do this using some new HTML features currently only available in Chrome I believe. Basically you save the contents of the DIV using the FileSystem APi and then create a link that has a download attribute pointing to the file.