RobB wrote:
Pretty much answers your Q...Object.insertBefore() 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">Read between the lines</h1>
<script language="JavaScript">
var insultObj = document.createTextNode("Could you *be* any dumber");
var replyObj = document.createTextNode("Yes, just give me some time");
heading = document.getElementById("heading");
heading.parentNode.insertBefore(insultObj, heading);
heading.parentNode.insertBefore(replyObj, null);
</script>
</body>
</html>