Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

DOMParentNode

DOMParentNode is an interface introduced in version 8.0 for DOM nodes that can have children. It is implemented by DOMDocument, DOMElement, and DOMDocumentFragment.

It provides prepend() and append() methods to insert nodes as first or last children, and childElementCount, firstElementChild, lastElementChild properties.

<?php

    $dom = new DOMDocument;
    $dom->loadHTML('<p>Hello</p>');
    $p = $dom->getElementsByTagName('p')->item(0);
    $p->append($dom->createTextNode(' world'));

?>

Documentation

See Also