Re: DOM - Replacing text in the DOM
On Sat, 30 Sep 2006 07:04:02 -0700, Tyrone Slothrop <ts@paranoids.com>
wrote:
>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.
************************************************** *********************************
Thanks for your answer. However, I want this to be just a PHP thing. I
am going to be using AJAX with the site too, and I have that working,
but I have to cater for those who do not have javascript. I will do
this with PHP rather than mess with html because I want to store some
of my content in a database. - providing I can get an answer as to
what commands I need to use to replace the text in the DOM as in my
original post.
************************************************** ********************************
I can do what I want to do in Javascript but, as I said, I don't want
to use javascript for this task. I don't thiink 'innerHTML' on
javascript is part of the official DOM even though the main browsers
support it. For that reasonm I don't tend to use it. It takes more
code in Javascript to do it via the official DOM commands I do admit.
Remove 'no_spam_' from email address.
Skype Free Zone!!
|