note 117380 added to domnode.insertbefore
| From: | jarry1250 at gmail dot com | Date: | Sat, 30 May 2015 13:59:07 +0000 |
| Subject: | note 117380 added to domnode.insertbefore | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-202709@lists.php.net to get a copy of this message | ||
Note that supplying the same node for $newnode and $refnode leads to an E_WARNING
("Couldn't add newnode as the previous sibling of refnode"). For example imagine one
wanted to make $newnode the first child of its parent by doing:
<?php
$firstSibling = $newnode->parentNode->firstChild;
// Bad:
$newnode->parentNode->insertBefore( $newnode, $firstSibling );
?>
This would generate a warning if it already was the first child of its parent, since $newnode and
$firstSibling are identical. Easy to work around though:
<?php
$firstSibling = $newnode->parentNode->firstChild;
// Better:
if( $newnode !== $firstSibling ) {
$newnode->parentNode->insertBefore( $newnode, $firstSibling );
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 82.2.183.78
----
Manual Page -- http://php.net/manual/en/domnode.insertbefore.php
Edit -- https://master.php.net/note/edit/117380
Del: integrated -- https://master.php.net/note/delete/117380/integrated
Del: useless -- https://master.php.net/note/delete/117380/useless
Del: bad code -- https://master.php.net/note/delete/117380/bad+code
Del: spam -- https://master.php.net/note/delete/117380/spam
Del: non-english -- https://master.php.net/note/delete/117380/non-english
Del: in docs -- https://master.php.net/note/delete/117380/in+docs
Del: other reasons-- https://master.php.net/note/delete/117380
Reject -- https://master.php.net/note/reject/117380
Search -- https://master.php.net/manage/user-notes.php