Javascript - get the code from the DOM of a given url

I want to get the DOM code from a web page in a given url.

Right now I have been trying jQuery:

$.get( "http://localhost/test.html", function( data ) {

Open in new window

But it's just giving me the actual source code and not the code given after the page is executed in the browser.

There are some variable values that are only displayed when in the DOM and not shown in the source code so I need to get the code in the DOM.

How can I do this?
Who is Participating?
Julian HansenConnect With a Mentor Commented:
The $.get only fetches the referenced page - remember it is the requesting browser that interprets the page not the server that sends it.

What you can do is load the script into an iframe and then query the iframe when it is loaded.

With jQuery this can be done something like this
$(function() {
	var elm = $('<iframe>').hide();
	elm[0].src = 'http://localhost/test.html';
	elm.load(function() {
		// access iframe with elm.contents() 

Open in new window

This will not work if the src domain / port / protocol is different from the host page.
Dave BaldwinFixer of ProblemsCommented:
The 'DOM' exists Only after the page has been loaded into a browser.  Loading the source as text like you are doing will never get the 'DOM'.
error2013Author Commented:
So, how can I get the DOM?
Dave BaldwinFixer of ProblemsCommented:
You can only get things from the DOM by loading the page into the browser.  The DOM (Document Object Model) is created when the browser processes a page.  It does not otherwise exist.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.