Modern DOM library written in PHP for HTML documents
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1.6 KiB

title
ContainerNode::appendChild

ContainerNode::appendChild — Adds new child at the end of the children

Description

public ContainerNode::appendChild ( \DOMNode $node ) : \DOMNode|false

This function appends a child to an existing list of children or creates a new list of children. The child can be created with e.g. Document::createElement(), Document::createTextNode() etc. or simply by using any other node.

When using an existing node it will be moved.

Warning Only the following element types may be appended to any node using Node and subject to hierarchy restrictions depending on the type of node being appended to:

Note that \DOMAttr is missing from this list.

Parameters

node
The new node.

Examples

Example #1 Adding a child to the body

<?php

namespace MensBeam\HTML;

$dom = new Document();
$dom->loadHTML('<!DOCTYPE html><html><head><title>Ook!</title></head><body></body></html>');

$node = $dom->createElement('br');
$dom->body->appendChild($node);

?>