the innerHTML of page

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jun 2008
Posts: 10
Reputation: SirDorius is an unknown quantity at this point 
Solved Threads: 1
SirDorius SirDorius is offline Offline
Newbie Poster

the innerHTML of page

 
0
  #1
Jun 12th, 2008
I'm trying to get some HTML code from a page. The only way to do this that I know of is
  1. 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?
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 14
Reputation: drago865 is an unknown quantity at this point 
Solved Threads: 1
drago865 drago865 is offline Offline
Newbie Poster

Re: the innerHTML of page

 
0
  #2
Jun 12th, 2008
Hi, SirDorius.

Instead of using
  1. document.getElementById(id).innerHTML;
You could use
  1. 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:
  1. document.getElementsByTagName("div")[2].innerHTML;

Hope that helps,

Adam
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 10
Reputation: SirDorius is an unknown quantity at this point 
Solved Threads: 1
SirDorius SirDorius is offline Offline
Newbie Poster

Re: the innerHTML of page

 
0
  #3
Jun 12th, 2008
Thanks Adam, that did help a lot!

Cheers!
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 206
Reputation: plazmo is an unknown quantity at this point 
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: the innerHTML of page

 
0
  #4
Jun 13th, 2008
the inner html of the whole html document is
document.childNodes[1].innerHTML

or
document.body.innerHTML
if you just want the bodys html
Last edited by plazmo; Jun 13th, 2008 at 4:55 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 10
Reputation: SirDorius is an unknown quantity at this point 
Solved Threads: 1
SirDorius SirDorius is offline Offline
Newbie Poster

Re: the innerHTML of page

 
0
  #5
Jun 13th, 2008
Thanks, document.body.innerHTML should be useful too
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC