Bug 105586 - appendChild for tr element to table element fails with DOM Exception HIERARCHY_REQUEST_ERR
Summary: appendChild for tr element to table element fails with DOM Exception HIERARCH...
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Unclassified
Component: kjs (show other bugs)
Version: unspecified
Platform: openSUSE RPMs Linux
: NOR normal (vote)
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-05-13 10:13 UTC by Jos van den Oever
Modified: 2005-05-24 01:24 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
demonstration of the javascript (866 bytes, text/html)
2005-05-13 10:14 UTC, Jos van den Oever
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jos van den Oever 2005-05-13 10:13:07 UTC
Version:            (using KDE KDE 3.4.0)
Installed from:    SuSE RPMs

Calling table.appendChild(tr) where table is a <table> element and tr is a <tr> element fails with error HIERARCHY_REQUEST_ERR. This code works in Mozilla and Opera.

What elements does <table> accept? Is there a workaround?
Comment 1 Jos van den Oever 2005-05-13 10:14:50 UTC
Created attachment 11016 [details]
demonstration of the javascript
Comment 2 Jos van den Oever 2005-05-13 10:36:26 UTC
Ok, I just found a workaround. Instead of writing:
  table.appendChild(tr);
One can write:
  var tbody = document.createElement('tbody');
  table.appendChild(tbody);
  var tr = document.createElement('tr');
  tbody.appendChild(tr);

I'm not sure what the spec says about this, so I'm not really sure if this is a bug anymore.
Comment 3 Jos van den Oever 2005-05-13 10:38:06 UTC
Since a table can have more than one tbody element, the Konqueror implementation is very strict, but not wrong. Therefore, the bug has been resolved.
Comment 4 David Faure 2005-05-24 01:22:48 UTC
Actually it's wrong that something, which works in Mozilla and IE, doesn't work in Konq (KHTML). Someone else reported this on IRC, and I fixed it.
Comment 5 David Faure 2005-05-24 01:24:42 UTC
SVN commit 417591 by dfaure:

Allow javascript to insert a TR directly into a TABLE, creating a TBODY section if needed
BUG: 105586


 M  +5 -0      ChangeLog  
 M  +13 -0     html/html_tableimpl.cpp  
 M  +1 -0      html/html_tableimpl.h  


--- trunk/KDE/kdelibs/khtml/ChangeLog #417590:417591
@@ -1,3 +1,8 @@
+2005-05-24  David Faure  <faure@kde.org>
+
+        * html/html_tableimpl.cpp (appendChild): Allow javascript to insert
+        a TR directly into a TABLE, creating a TBODY section if needed (bug #105586).
+
 2005-05-21  Harri Porten  <porten@kde.org>
 
 	* html/html_documentimpl.cpp: emit onload event even if the
--- trunk/KDE/kdelibs/khtml/html/html_tableimpl.cpp #417590:417591
@@ -307,6 +307,19 @@
         exceptioncode = DOMException::INDEX_SIZE_ERR;
 }
 
+NodeImpl *HTMLTableElementImpl::appendChild(NodeImpl *child, int &exceptioncode)
+{
+    if(child->id() == ID_TR) { // #105586, allow to insert a TR inside a TABLE, creation section as needed
+        // See insertRow
+        if (!firstBody && !head && !foot && !hasChildNodes())
+            setTBody( new HTMLTableSectionElementImpl(docPtr(), ID_TBODY, true /* implicit */) );
+        Q_ASSERT( firstBody );
+        if (firstBody)
+            return firstBody->appendChild( child, exceptioncode );
+    }
+    return HTMLElementImpl::appendChild( child, exceptioncode );
+}
+
 NodeImpl *HTMLTableElementImpl::addChild(NodeImpl *child)
 {
 #ifdef DEBUG_LAYOUT
--- trunk/KDE/kdelibs/khtml/html/html_tableimpl.h #417590:417591
@@ -95,6 +95,7 @@
 
     // overrides
     virtual NodeImpl *addChild(NodeImpl *child);
+    virtual NodeImpl *appendChild( NodeImpl *newChild, int &exceptioncode );
     virtual void parseAttribute(AttributeImpl *attr);
     virtual void attach();