emulate removechild in IE 4?

B

bulk88

How can I emulate DOM level 1 removeChild in IE 4? I already figured
out to emulate getElementById by doing this

if((!document.getElementById) && document.all)
{document.getElementById = function(id){return document.all[id];};
}

Is there something similar for removeChild?
 
M

Michael Winter

How can I emulate DOM level 1 removeChild in IE 4?

With enormous difficulty.
I already figured out to emulate getElementById by doing this

if((!document.getElementById) && document.all)
{document.getElementById = function(id){return document.all[id];};
}

That's an approximation as the all collection will return elements that
match by either id or name, and if there is more than one result a
collection, rather than a single reference, will be returned. Be aware of
that when you're producing your mark-up so that you will only every get
one reference. Alternatively, see the second example at
Is there something similar for removeChild?

You might be able to use the innerHTML property to remove the element,
though that would depend on the parent element in question (IE4 doesn't
implement innerHTML on all elements).

Good luck,
Mike
 
M

Martin Honnen

How can I emulate DOM level 1 removeChild in IE 4?

Well IE 4 doesn't know text nodes for instance so you can't write a
method for all types of child nodes that exist in DOM Level 1.
If you have an element node (e.g. accessed with
element.children[0]
) then you can simply set outerHTML to an empty string
if (element.children && element.children[0]) {
element.children[0].outerHTML = '';
}
 

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,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top