User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 392,054 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,290 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 896 | Replies: 4 | Solved
Reply
Join Date: Jun 2008
Posts: 10
Reputation: SirDorius is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
SirDorius SirDorius is offline Offline
Newbie Poster

the innerHTML of page

  #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?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2006
Posts: 13
Reputation: drago865 is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
drago865 drago865 is offline Offline
Newbie Poster

Re: the innerHTML of page

  #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  
Join Date: Jun 2008
Posts: 10
Reputation: SirDorius is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
SirDorius SirDorius is offline Offline
Newbie Poster

Re: the innerHTML of page

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

Cheers!
Reply With Quote  
Join Date: Aug 2005
Location: Ohio
Posts: 204
Reputation: plazmo is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 16
plazmo's Avatar
plazmo plazmo is offline Offline
Posting Whiz in Training

Re: the innerHTML of page

  #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 3:55 pm.
Reply With Quote  
Join Date: Jun 2008
Posts: 10
Reputation: SirDorius is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
SirDorius SirDorius is offline Offline
Newbie Poster

Re: the innerHTML of page

  #5  
Jun 13th, 2008
Thanks, document.body.innerHTML should be useful too
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:35 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC