Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2006, 06:02 AM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default put part of html in string DOM

Hi,

I like to put a part of a page in a string using DOM javascript.

Suppose I have the following html page
Code:
<html>
<head>
</head>
<body>
  <div class='content'>
    <h1>text</h1>
    <p>even more text</p>
    bla bla bla
  <div>
<body>
</html>
now I would like to put all html inside the div tags inside a string.
The html in the string would be
Code:
  <h1>text</h1>
  <p>even more text</p>
  bla bla bla
Can anyone help me with this.

Thnx


__________________________________________________ ________
This is my junk I'm gona eat it
 
Old February 20th, 2006, 11:38 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Dj,

I think this might be what you're after (if I'm interpreting your question correctly).

<script language ="javascript">
function strDivs(){
var htmlElement = document.getElementsByTagName("DIV")

        for (i = 0; i <=htmlElement.length -1; i++)
        {
        htmlElement[i].innerHTML = "<h1>text</h1><p>even more text</p>bla bla bla"
        }
}
</script>

Cheers
Joe

 
Old February 20th, 2006, 11:43 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Actually I just realised i interpreted that the wrong way round lol:

<script language ="javascript">
function strDivs(){
var htmlElement = document.getElementsByTagName("DIV")

        for (i = 0; i <=htmlElement.length-1; i++)
        {
        htmlStr = htmlElement[i].innerHTML
        alert(htmlStr)//remember to remove this......
        }
}
</script>


HTH
Cheers!
Joe

 
Old February 22nd, 2006, 04:28 AM
Friend of Wrox
 
Join Date: Nov 2005
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thnx,

that helped me out :)

__________________________________________________ ________
This is my junk I'm gona eat it





Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML DOM - clone form element could not be aligned Shibu Javascript 5 November 15th, 2008 11:24 PM
html part inside xml RoeZ XSLT 3 November 28th, 2007 08:18 AM
How to get html code for the selected part of the suryasimha General .NET 2 August 27th, 2007 02:32 PM
Getting Part of a String needelp Access VBA 4 September 19th, 2006 06:22 AM
How this HTML DOM established? Crazy4C Javascript 1 April 16th, 2006 02:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.