[Greasemonkey] document.replaceChild

Matt Labrum darktempler at gmail.com
Sat Apr 23 03:54:15 EDT 2005

Im trying to write a script to replace the textarea of a site with
another element but I cant seem to get document.replaceChild to do it.

the Javascript im using is

var textarea = document.getElementsByTagName("textarea")[0];
var newnode = document.createElement("p");
newnode.innerHTML = "TEST";
document.replaceChild(newnode, textarea);

and In the target webpage theres a text area like

<textarea name="message" rows="7" cols="70" wrap="virtual"

Also I know I've got the right textbox in the varible textarea because
I've used
document.getElementsByTagName("textarea")[0].innerHTML = "hello";
and it showed hello in my textarea.

the error it says when I use it is 
Error: uncaught exception: [Exception... "Node cannot be inserted at
the specified point in the hierarchy"  code: "3" nsresult: "0x80530003
"http://www.msghelp.net/showthread.php?tid=43421 Line: 21"]

And I've tried creating some test cases for myself using sites that
I've created but I cant seen to get it to work :( maby Im using
replaceChild wrong?

More information about the Greasemonkey mailing list