View Single Post

  #2 (permalink)  
Old 09-30-2006
Tyrone Slothrop
 
Posts: n/a
Default Re: DOM - Replacing text in the DOM

On Sat, 30 Sep 2006 11:48:56 GMT, Brian A
<no_spam_bca1000@hotmail.com> wrote:

>I want to miror what I can do in javascript with regard to some DOM
>manipulation. I have done lots of PHP programming but not in relation
>to the DOM.
>
>I have a html test file :-
>
>.........................
><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
>"http://www.w3.org/TR/html4/loose.dtd">
>
><html><head><title></title></head><body>
>
><div id="books">This is the text in books</div>
>
></body></html>
>...................
>
>I can access the text 'This is the text in books' with the code:-
>
>........................................
><?php
>$doc = new DomDocument();
>$doc->loadHTMLFile("test.html");
>$text=$doc->getElementById('books')->firstChild->textContent;
>echo "The text is ".$text;
>?>

....
>How do I replace the text in the DOM?


I have never used these functions. My approach as always been more of
of JS/DHTML/AJAX/COMET. However, if you can call the text you want
replaced dynamically, replacing the text on a web page is fairly
simple:

<script type="text/javascript">
document.getElementById(''books').innerHTML = <?=$text?>;
</script>

How you actually trigger the display is not shown here but, I assume,
you will have to create a JS function to do it.

You might Google AJAX and COMET for an alternative approach.

Reply With Quote