innerHTML problem?

Tobias Anton TA at ESC-Electronics.de
Fri Sep 3 16:01:04 BST 2004


On Donnerstag, 2. September 2004 18:05, David Faure wrote:
> On Thursday 02 September 2004 18:06, Leo Savernik wrote:
> > Am Donnerstag, 2. September 2004 16:14 schrieb David Faure:
> > > On Tuesday 31 August 2004 15:42, Martin Jordan wrote:
> > > > hi there,
> > > >
> > > > shouldn't document.getElementById( ... ).innerHTML grant access to
> > > > the inner value of the html-tag and not to the whole itself?
> > >
> > > Indeed.
> > >
> > > Here's a patch that fixes it for your testcase (mostly taken from
> >
> > [...]
> >
> > Here's a simpler patch. Please review.
>
> Hmm, indeed. Any idea why innerText() does it the complex way?
It's supposed to be the iterative equivalent to the recursive algorithm in 
leo's patch. For a recursive variant, a new virtual method textToString() 
would have to be added to the classes NodeImpl, TextImpl and HTMLElementImpl.
I guess that seemed more complicated than the iterative solution.

> It seems that for an element without children it's going to get the text of
> the next sibling, which sounds broken...
Exactly. This line is missing:

===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_elementimpl.cpp,v
retrieving revision 1.179
diff -u -3 -p -r1.179 html_elementimpl.cpp
--- html/html_elementimpl.cpp   13 Jun 2004 17:08:24 -0000      1.179
+++ html/html_elementimpl.cpp   3 Sep 2004 13:54:53 -0000
@@ -449,6 +449,8 @@ DOMString HTMLElementImpl::innerText() c
     while(n) {
         if(n->firstChild())
             n = n->firstChild();
+       else if (n == this)
+           break;
         else if(n->nextSibling())
             n = n->nextSibling();
         else {

One of the most frequent errors of iterative dom traversal algorithms :-)

Cheers
-- Tobias





More information about the kfm-devel mailing list