[thelist] DOM Javascript - childNodes
liorean
liorean at f2o.org
Wed Dec 17 16:36:55 CST 2003
Mark Howells wrote:
> I'm coding a function to join several HTML forms together on a page and
> submit them as one, using DOM Javascript. I parse through the
> childNodes of the main forms, then copy the lot into a new form and
> submit it.
Why not move them? It's as simple as appending them to the new form,
they will be automatically removed from their original position.
> I am new to DOM JS code and stuck at the point where I want to delete
> all the dynamic form elements. I see that I can ditch the whole form
> and all children using obj.removeChild(true), but only want to ditch the
> children, not the form itself. Do I have to loop through the child
> elements and delete them one by one, or am I missing something? What's
> the most efficient solution?
Remember, childNodes is all types of nodes, not only elements...
You'd have to loop through it and remove all nodes of a type you want to
remove. A perhaps better approach is to replace the form element with a
shallow clone of itself, as that provided by
oFormElement.cloneNode(false), like this:
oFormElement.parentNode.replaceChild(
oFormElement.cloneNode(false),
oFormElement);
--
liorean <mailto:liorean at user.bip.net>
ViewStyles, ViewScripts, ToggleStyles and GraphicsInfo bookmarklets and
Theme Switcher, Cookies Handler scripts:
<http://liorean.web-graphics.com/>
More information about the thelist
mailing list