-
-
Save strarsis/d8b5410e12b274b2f987429accc10ae5 to your computer and use it in GitHub Desktop.
why doesn't the DOM spec include an insertAfter method, srsly guys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** Inserts a new node after a given reference node. Basically it is the complement to the DOM specification's | |
* insertBefore() function. | |
* @param \DOMNode $newNode The node to be inserted. | |
* @param \DOMNode $referenceNode The reference node after which the new node should be inserted. | |
* @return \DOMNode The node that was inserted. | |
*/ | |
function insertAfter(\DOMNode $newNode, \DOMNode $referenceNode) | |
{ | |
if($referenceNode->nextSibling === null) { | |
return $referenceNode->parentNode->appendChild($newNode); | |
} else { | |
return $referenceNode->parentNode->insertBefore($newNode, $referenceNode->nextSibling); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment