0

I would like to use jQuery to replace the contents of an HTML tag with a file.

I have the following code: $("html").html(hi.html).

While it works if I instead put a quote, it doesn't work if I put a file. How do I achieve this?

sodawillow
  • 12,497
  • 4
  • 34
  • 44
  • It's not clear what you're asking. Perhaps you're looking for `.load()`? – elixenide Nov 23 '15 at 17:22
  • 1
    @EdCottrell is right, I think load() is what you want. .html() will replace the innerHTML of an element with HTML passed as a string containing HTML tags. While .load() will download a file and load its content into the element. – Gregg Duncan Nov 23 '15 at 18:04

1 Answers1

0

Your question seems a bit ambiguous. I am assuming you are trying to load a local file rather than a file served from a server. If you are looking for later, then gregg's answer will suffice.

You can use html5's File reader api to read contents of a file stored locally on your machine. Sample implementation: How to open a local disk file with Javascript?.

Helpful links:

Hope this helps if this is what you are looking for.

Community
  • 1
  • 1
SaurabhM
  • 7,995
  • 1
  • 15
  • 20