954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

the innerHTML of page

I'm trying to get some HTML code from a page. The only way to do this that I know of is

document.getElementById('id').innerHTML = 'newhtml';

But the problem is that the page is taken from the web and it has no IDs to get and I can't modify it by putting IDs.
So is there a way to get the innerHTML of the whole page so I can search for certain strings afterwards?

SirDorius
Newbie Poster
10 posts since Jun 2008
Reputation Points: 10
Solved Threads: 1
 

Hi, SirDorius.

Instead of using

document.getElementById(id).innerHTML;


You could use

document.getElementsByTagName(tag)[0].innerHTML;


This method will give you an array of all the elements on the page with that tag name. Just access each tag like you would access an array.

For example, if you wanted to get the inner HTML of the third division on the page you could use:

document.getElementsByTagName("div")[2].innerHTML;


Hope that helps,

Adam

drago865
Newbie Poster
14 posts since Jan 2006
Reputation Points: 10
Solved Threads: 1
 

Thanks Adam, that did help a lot!

Cheers!

SirDorius
Newbie Poster
10 posts since Jun 2008
Reputation Points: 10
Solved Threads: 1
 

the inner html of the whole html document is
document.childNodes[1].innerHTML

or
document.body.innerHTML
if you just want the bodys html

plazmo
Posting Whiz in Training
207 posts since Aug 2005
Reputation Points: 23
Solved Threads: 16
 

Thanks, document.body.innerHTML should be useful too

SirDorius
Newbie Poster
10 posts since Jun 2008
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You