QAH
QAH

Reputation: 4280

Load html document in javascript from text

Is it possible to load an html document into a DOM javascript object so that you can read the elements in the document? For example, if I have a file on the server Test.html. Can the page Hello.html call javascript code to load Test.html into a DOM object?

Please let me know.

Thanks

Upvotes: 5

Views: 2376

Answers (2)

hegemon
hegemon

Reputation: 6764

Using jQuery:

$("#where_to_paste").load('Test.html');

Upvotes: 1

rahul
rahul

Reputation: 187030

You can issue an AJAX request to the new page and get the result as HTML. Then you can bind the HTML to the DOM element.

If you can use a javascrpt library like jQuery there is a load method which loads the data from server and place the returned HTML in a DOM object.

See .load()

$('yourselector').load('Test.html', function() {
  alert('Load was performed.');
});

Upvotes: 2

Related Questions