• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/web/dom/node.php
  • Класс: BitrixMainWebDOMNode
  • Вызов: Node::insertBefore
public function insertBefore(Node $newChild, Node $refChild = null, $removeExist = true)
{
	if($newChild->getOwnerDocument() !== $this->getOwnerDocument())
	{
		throw new DomException('Node newChild was created from a different document than the one that created this node', DomException::WRONG_DOCUMENT_ERR);
	}

	if($refChild && !$this->haveChild($refChild))
	{
		throw new DomException('Node refChild not found in childList', DomException::NOT_FOUND_ERR);
	}

	if ($removeExist && $this->haveChild($newChild))
	{
		$this->removeChild($newChild);
	}



	$childList = $this->getChildNodesArray();
	if($refChild)
	{
		$childListNew = array();
		foreach($childList as $child)
		{
			if($refChild === $child)
			{
				$childListNew[] = $newChild;
			}
			$childListNew[] = $child;
		}
		$childList = $childListNew;
	}
	else
	{
		$childList[] = $newChild;
	}

	$this->setChildNodesArray($childList);
	$newChild->setParentNode($this);

	return $newChild;
}