NS/Mozilla/Firefox mergeAttributes problem

M

mikejr83

I've been working on a project converting some IE code to be
cross-browser complient. I've run into a little problem figuring out
how to migrate the IE specific mergeAttributes function to something
similar that is complient in NS/Mozilla/Firefox browsers.

Currently I have this basic code
row = this.insertRow(position) //I'm inserting a row into "this" table
row.mergeAttributes(this.templateRow); //here I'm basically "copying"
this template row to the newly created row
// clone all the cells from the template to the new row.
var cells = this.templateRow.childNodes;
for (var i = 0; i < cells.length; i++)
{
var cell = cells.cloneNode(true);
row.appendChild(cell);
}

Basically, I need to come up with a way to copy the attributes from the
the template row to the new row along with all the cells.

I've tried using the cloneNode method on the template row and assigning
the returned element to the row object that was created. This does not
work. Inside these row objects properties have been added, and if I'm
reading this code correctly, it appears that some TR level functions
have been added as well.

Thanks in advance. This has been wreaking some havoc on me for a while
and I don't currently see a solution to it. Thanks!

Mike G.
 
T

Thomas 'PointedEars' Lahn

I've been working on a project converting some IE code to be
cross-browser complient. I've run into a little problem figuring out
how to migrate the IE specific mergeAttributes function to something
similar that is complient in NS/Mozilla/Firefox browsers.

Currently I have this basic code
row = this.insertRow(position) //I'm inserting a row into "this" table

For this to work, `this' would be required to be a reference to a
HTMLTableRowElement object. But that would require that code to be in
either a method of HTMLTableRowElement.prototype (which is not possible
in the IE DOM yet, and discovered recently to be not fully implemented
in the Gecko DOM yet), or a method of the HTMLTableRowElement object
itself (which is recommended against, as that object is a host object).

And do you declare `row' before you define it? If no, there is another
issue as well, as that "variable" is rather a property of the Global
Object, or a property of another globally available host object that
imposes restrictions on property write access (IE DOM); if there is an
element with ID or name `row', there will be no "variable" but a runtime
error.

So much for "cross-browser compliance".
row.mergeAttributes(this.templateRow); //here I'm basically "copying"

Since you say below that the result of the copy process is the source of
your problems, it would have been wise if you posted its source code.
this template row to the newly created row

Source code should be posted so that it still makes sense when becoming
subject to automatic word-wrapping at about column 76.
// clone all the cells from the template to the new row.
var cells = this.templateRow.childNodes;
for (var i = 0; i < cells.length; i++)
{
var cell = cells.cloneNode(true);
row.appendChild(cell);
}

Basically, I need to come up with a way to copy the attributes from the
the template row to the new row along with all the cells.


That is what Node::cloneNode() is for.
I've tried using the cloneNode method on the template row and assigning
the returned element to the row object that was created. This does not
work. Inside these row objects properties have been added, and if I'm
reading this code correctly, it appears that some TR level functions
have been added as well.

You are not making any sense. "TR level functions"? It strikes me that
your "problem" is that _you_ have augmented HTMLTableRowElement.prototype
or the corresponding HTMLTableRowElement object and now are wondering that
the copy either inherits the prototype object's or has the original object's
properties. Well, this behavior would be by design. Simply do not
augment the prototype object or the element object in the first place
then, but pass references to the corresponding element object instead.


PointedEars
 

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

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,167
Latest member
SusanaSwan
Top