Internet Explorer 6.0 and removeChild

330 views
Skip to first unread message

-berg-

unread,
Mar 7, 2007, 7:54:51 PM3/7/07
to
Hello all,

It appears IE 6.0.2800.1106 doesn't like what it creates?
Can anyone shed light on IE and the removeChild argument?

To boil it down to simplicity, I have a function:

function addFeature(parent,name,feat)
{
newLayer = document.createElement("input");
newLayer.type = "hidden";
newLayer.name = "layer";
newLayer.id = "lyr"+feat;
newLayer.value = name;
parent.appendChild(newLayer); //Ok with both Firefox and IE

// IE can't remove what it just added?
// Test line of code to get IE to barf with "Invalid Argument"
parent.removeChild(newLayer); // Ok with Firefox; IE barfs

}

the "Test line of code" parent.removeChild(newLayer) barfs on
IE with "Invalid Argument". The "parent" is a named form.

In the "real version", I'm building up elements for a form submit,
and I can verify that in the "real version" (that does not have
the removeChild there) the appendChild works as expected by
inspecting the URL at the CGI end; the new form input elements are
created. So, "parent.appendChild(newLayer);" works fine; with both
IE and Firefox, the appendChild works as expected with the URL I
intend to see being created. It's the "removeChild" that has the
problem.

The removeChild is in that function now for debug, because elsewhere
in the javascript, I need to remove previously added things, and then
IE pukes with "Invalid Argument". Of course, and almost naturally as
expected this works fine in Firefox with the form elements
"inflating" and "deflating" as it completes the "appendChild" and
"removeChild".

For general (Google?) use, the URL I'm building ends up looking like:
<bla>mycgi?layer=val0&;layer=val2&layer=val3&layer=val4 etc etc
as needed, and fulfilled by the "appendChild" calls. Then the next
iteration it may be:
<bla>mycgi?layer=val0&;layer=val2
or
<bla>mycgi?layer=val0&;layer=val2&layer=val3&layer=val4&layer=val5

Mark
----------------------------------------------------------------

(To de-spam the rtn addr, take out the "garbage.")

-berg-

unread,
Mar 8, 2007, 7:27:31 PM3/8/07
to
On Thu, 08 Mar 2007 00:54:51 GMT, m...@garbage.storm.ca (-berg-) wrote:

>// IE can't remove what it just added?
>// Test line of code to get IE to barf with "Invalid Argument"
> parent.removeChild(newLayer); // Ok with Firefox; IE barfs

One can only guess, but to removeChild, IE was happy with this instead
of parent.removeChild(newLayer);


layer.parentNode.removeChild(layer);

-berg-

unread,
Mar 8, 2007, 7:33:14 PM3/8/07
to
On Fri, 09 Mar 2007 00:27:31 GMT, m...@garbage.storm.ca (-berg-) wrote:

sorry, it should have read
newLayer.parentNode.removeChild(newLayer);

..in other words...this "newLayer"'s parent is requested to remove
a child of this "newLayer".

So instead of:
parent.appendChild(newLayer);
parent.removeChild(newLayer);

one has
parent.appendChild(newLayer);
newLayer.ParentNode.removeChild(newLayer);

..only in IE of course. Firefox understands it the first way.
..The intuitive way.

-berg-

unread,
Mar 8, 2007, 7:37:13 PM3/8/07
to
On Fri, 09 Mar 2007 00:33:14 GMT, m...@garbage.storm.ca (-berg-) wrote:

..and for completeness sake, the script now reads:
try {
form.removeChild(newLayer);
} catch (e)
{
newLayer.parentNode.removeChild(newLayer);
}

IE pulls an exception and it runs the second line. Sheesh.

Reply all
Reply to author
Forward
0 new messages