<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Adds a new child before a reference node</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="domnode.haschildnodes.html">DOMNode::hasChildNodes</a></div> <div class="next" style="text-align: right; float: right;"><a href="domnode.isdefaultnamespace.html">DOMNode::isDefaultNamespace</a></div> <div class="up"><a href="class.domnode.html">DOMNode</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="domnode.insertbefore" class="refentry"> <div class="refnamediv"> <h1 class="refname">DOMNode::insertBefore</h1> <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">DOMNode::insertBefore</span> — <span class="dc-title"> Adds a new child before a reference node </span></p> </div> <div class="refsect1 description" id="refsect1-domnode.insertbefore-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="modifier">public</span> <span class="type"><a href="class.domnode.html" class="type DOMNode">DOMNode</a></span> <span class="methodname"><strong>DOMNode::insertBefore</strong></span> ( <span class="methodparam"><span class="type"><a href="class.domnode.html" class="type DOMNode">DOMNode</a></span> <code class="parameter">$newnode</code></span> [, <span class="methodparam"><span class="type"><a href="class.domnode.html" class="type DOMNode">DOMNode</a></span> <code class="parameter">$refnode</code></span> ] )</div> <p class="para rdfs-comment"> This function inserts a new node right before the reference node. If you plan to do further modifications on the appended child you must use the returned node. </p> </div> <div class="refsect1 parameters" id="refsect1-domnode.insertbefore-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">newnode</code></em></span> <dd> <p class="para"> The new node. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">refnode</code></em></span> <dd> <p class="para"> The reference node. If not supplied, <em><code class="parameter">newnode</code></em> is appended to the children. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-domnode.insertbefore-returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> The inserted node. </p> </div> <div class="refsect1 errors" id="refsect1-domnode.insertbefore-errors"> <h3 class="title">Errors/Exceptions</h3> <p class="para"> <dl> <dt> <span class="term"><strong><code>DOM_NO_MODIFICATION_ALLOWED_ERR</code></strong></span> <dd> <p class="para"> Raised if this node is readonly or if the previous parent of the node being inserted is readonly. </p> </dd> </dt> <dt> <span class="term"><strong><code>DOM_HIERARCHY_REQUEST_ERR</code></strong></span> <dd> <p class="para"> Raised if this node is of a type that does not allow children of the type of the <em><code class="parameter">newnode</code></em> node, or if the node to append is one of this node's ancestors or this node itself. </p> </dd> </dt> <dt> <span class="term"><strong><code>DOM_WRONG_DOCUMENT_ERR</code></strong></span> <dd> <p class="para"> Raised if <em><code class="parameter">newnode</code></em> was created from a different document than the one that created this node. </p> </dd> </dt> <dt> <span class="term"><strong><code>DOM_NOT_FOUND</code></strong></span> <dd> <p class="para"> Raised if <em><code class="parameter">refnode</code></em> is not a child of this node. </p> </dd> </dt> </dl> </p> </div> <div class="refsect1 seealso" id="refsect1-domnode.insertbefore-seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"> <span class="methodname"><a href="domnode.appendchild.html" class="methodname" rel="rdfs-seeAlso">DOMNode::appendChild()</a> - Adds new child at the end of the children</span></li> </ul> </p> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="domnode.haschildnodes.html">DOMNode::hasChildNodes</a></div> <div class="next" style="text-align: right; float: right;"><a href="domnode.isdefaultnamespace.html">DOMNode::isDefaultNamespace</a></div> <div class="up"><a href="class.domnode.html">DOMNode</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>