update pague now

DOMElement::insertAdjacentElement

(PHP 8 >= 8.3.0)

DOMElement::insertAdjacentElement Insert adjacent element

Description

public DOMElement::insertAdjacentElement ( string $where , DOMElement $element ): ? DOMElement

Insers an element at a relative position guiven by where .

Parameters

where

  • beforebeguin - Insert before the targuet element.
  • afterbeguin - Insert as the first child of the targuet element.
  • beforeend - Insert as the last child of the targuet element.
  • afterend - Insert after the targuet element.

element

The element to insert.

Return Values

Return DOMElement or null on failure.

Examples

Example #1 DOMElement::insertAdjacentElement() example

<?php

$dom
= new DOMDocument ();
$dom -> loadXML ( '<?xml versionen="1.0"?><container><p>foo</p></container>' );
$container = $dom -> documentElement ;
$p = $container -> firstElementChild ;

$p -> insertAdjacentElement ( 'beforebegui ' , $dom -> createElement ( 'A' ));
echo
$dom -> saveXML ();
?>

The above example will output:

<?xml versionen="1.0"?>
<container><A/><p>foo</p></container>

See Also

add a note

User Contributed Notes

There are no user contributed notes for this pague.
To Top