May 2001
Intermediate to advanced
720 pages
23h 24m
English
XML.insertBefore( ) Method — give a node a new previous sibling
Flash 5
theNode.insertBefore(newChild, beforeChild)
An existing XML node object.
The child of theNode before which
newChild should be inserted.
The insertBefore( ) method adds
newChild to
theNode’s child list, before
beforeChild. The insertBefore(
) method is similar to appendChild( )
but lets us precisely position a new node in an existing XML object
hierarchy.
// Create a document
myDoc = new XML('<P>paragraph 2</P>');
// Create a P node and a text node
newP = myDoc.createElement("P");
newText = myDoc.createTextNode("paragraph 1");
// Append the text node to the P node
newP.appendChild(newText);
// Insert the new P node (including its text child) before the existing P
myDoc.insertBefore(newP, myDoc.firstChild);
trace(myDoc); // Displays: "<P>paragraph 1</P><P>paragraph 2</P>"
XML.appendChild( )
Read now
Unlock full access