innerHTML problem?
David Faure
faure at kde.org
Thu Sep 2 15:14:33 BST 2004
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 innerText()).
What's needed now is more testcases for it (to check that it works with more
complex cases, like multiple child nodes). Any chance you can provide that?
Index: html_elementimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_elementimpl.cpp,v
retrieving revision 1.179
diff -u -p -r1.179 html_elementimpl.cpp
--- html_elementimpl.cpp 13 Jun 2004 17:08:24 -0000 1.179
+++ html_elementimpl.cpp 2 Sep 2004 14:12:50 -0000
@@ -435,7 +435,29 @@ void HTMLElementImpl::removeCSSProperty(
DOMString HTMLElementImpl::innerHTML() const
{
- return toString();
+ DOMString text;
+ if(!firstChild())
+ return text;
+
+ const NodeImpl *n = this;
+ while(n) {
+ if(n->firstChild())
+ n = n->firstChild();
+ else if(n->nextSibling())
+ n = n->nextSibling();
+ else {
+ NodeImpl *next = 0;
+ while(!next) {
+ n = n->parentNode();
+ if(!n || n == (NodeImpl *)this ) goto end;
+ next = n->nextSibling();
+ }
+ n = next;
+ }
+ text += n->toString();
+ }
+ end:
+ return text;
}
DOMString HTMLElementImpl::innerText() const
--
David Faure, faure at kde.org, sponsored by Trolltech to work on KDE,
Konqueror (http://www.konqueror.org), and KOffice (http://www.koffice.org).
More information about the kfm-devel
mailing list