help with DOM row/cell with innerHTML

V

VK

The W3C DOM 2 HTML makes no statement that createElement and appendChild
cannot be used to add a new table row to a table.

The text "The create* and delete* methods on the table allow authors
to construct and modify tables." is not excluding other ways to create
and add rowgroups, rows or cells.

Besides method descriptions, there is the concept of DOM itself, where we
have a strict hierarchy of objects / elements from the top to the bottom
(and visa versa). It was the whole idea to start all this mess in the first
place.

IMHO it is hardly DOM-compliant to use the statement
document.createElement() as some kind of stay-alone universal object
factory. And it becomes recently a common practice even on official sample
code pages.

document.createElement(table) - fine by me: "add to the document structure
element Table"
document.createElement(tbody,...tr,td,...) - oops: "add to the document
structure element tBody..."

Sorry, but there is not such element in the document structure. It is an
object of the table object.

It should be either TOM, or:
var t = document.createElement(table);
var b = t.createElement(tbody);
....

If it doesn't work this way, so it was not intended to work this way, so
TOM.
 
L

Lasse Reichstein Nielsen

VK said:
document.createElement(table) - fine by me: "add to the document structure
element Table"
document.createElement(tbody,...tr,td,...) - oops: "add to the document
structure element tBody..."

Sorry, but there is not such element in the document structure. It is an
object of the table object.

I'll just refer to the first illustration of
<URL:http://www.w3.org/TR/DOM-Level-1/introduction.html>
(with the accompagnying text: "The DOM represents this table like this:")

The table structure *is* part of the entire document structure, and
it has been the intention of the W3C since DOM 1, as they clearly
show here.

There is nothing in the DOM specification that prevents you from doing:

table2.tBodies[0].appendChild(table1.rows[0]);

The row is not bound to the table that created it, or to which it was
first added. It *is* bound to the document that created it.

Also notict that in DOM HTML (both version 1 and 2), the
HTMLTableElement doesn't have a "createTBody()" method, so the only
way to create a TBody is to use document.createElement.

It should be either TOM, or:

There is no Table Object Model defined anywhere. There is a definition
of DOM objects in the HTML DOM that can be used to define tables.
Just as there is no Form Object Model, but there are objects in the
HTML DOM for form and input elements.

/L
 
M

Michael Winter

On Wed, 13 Oct 2004 20:33:55 +0200, Lasse Reichstein Nielsen

[snip]
There is nothing in the DOM specification that prevents you from doing:

table2.tBodies[0].appendChild(table1.rows[0]);

Though I'd only use appendChild if I was moving or cloning an existing
element unless there was some significant reason not to[1]. I'd like to
say the same about HTMLSelectElement.add, but appendChild seems more
reasonable than

var e;
try {
// W3C method
selObj.add(optObj, null);
} catch(e) {
// Microsoft method
selObj.add(optObj, -1); // or add(optObj);
}

Microsoft... *grrr*

[snip]
Also notict that in DOM HTML (both version 1 and 2), the
HTMLTableElement doesn't have a "createTBody()" method, so the only way
to create a TBody is to use document.createElement.

To me, that does appear to be an odd decision on the part of the W3C.
Providing such a method is good for at least two reasons (trivial as they
are):

1) Consistency

There are create and delete methods for the head and foot. Why not for the
body?

2) Scope

As a TBODY element can only exist within a table, creation of the element
should be the responsibility of the table as it is with other section
types. I suppose that could be an argument for other dependent objects,
such as list items (though not form controls as they can exist as
descendants of any block or inline element[2]).

I can't think of any reason why creating a TBODY element with
createElement is beneficial.

[snip]

Mike


[1] There aren't, are there?
[2] I only just realised that a form control can be the child of a link.
What should happen when such a control is clicked? The click event should
bubble up to the containing link, causing navigation. That just seems
weird to me.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,619
Members
45,314
Latest member
HugoKeogh

Latest Threads

Top