views:

136

answers:

2

Hello everyone! 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

+3  A: 

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.');
});
rahul
+2  A: 

Using jQuery:

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