RobB wrote:
Pretty much answers your Q...Object.inse rtBefore() takes two
arguments, the child node being inserted, and the (existing) sibling node you
want to follow it. It's invoked, naturally, on the parent node of both
children.
Ahhhh! It is invoked on the parent node. That is what I wasn't groking.
I was thinking the method was invoked on the node that you wanted to
"insert" the newChild "before".
Correctly, it is invoked on the parent and you pass the newChild and
and refChild parameters. "Reference CHILD" being the key point here ;).
-------------------------From W3 DOM2:
insertBefore
Inserts the node newChild before the existing child node refChild.
If refChild is null, insert newChild at the end of the list of
children.
.....
Parameters
newChild of type Node
The node to insert.
refChild of type Node
The reference node, i.e., the node before which the new node
must be inserted.
-------------------------
According to the W3 DOM the refChild parameter can be null if I don't
care about where my newChild is inserted. So I made refChild a null
keyword and it works great now. I guess the absence of a null keyword
is not equivalent to the presence of a null keyword. Thanks for the
help!
<html>
<head>
</head>
<body>
<h1 id="heading">Re ad between the lines</h1>
<script language="JavaS cript">
var insultObj = document.create TextNode("Could you *be* any dumber");
var replyObj = document.create TextNode("Yes, just give me some time");
heading = document.getEle mentById("headi ng");
heading.parentN ode.insertBefor e(insultObj, heading);
heading.parentN ode.insertBefor e(replyObj, null);
</script>
</body>
</html>