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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.
Julian HansenCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.