|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-03-01 07:11 UTC] gtisza at gmail dot com
Description: ------------ Removing a DOMElement from a HTML document does not refresh the id index; getElementById() will still return the removed element. (getElementsByTagName(), in contrast, works as expected.) Live test: https://3v4l.org/UQYTG Calling setIdAttribute() on the removed element apparently updates the index and fixes getElementById() behavior. It does not fix it for any children of the removed node, however. Test script: --------------- $doc = new DOMDocument; $doc->loadHTML('<html><body id="x"><div id="y"></div></body></html>'); $body = $doc->getElementById('x'); $div = $doc->getElementById('y'); $doc->getElementById('y'); // <div id="y"> PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 03:00:02 2025 UTC |
Corrected test script including the DOM removal: --------------- $doc = new DOMDocument; $doc->loadHTML('<html><body id="x"><div id="y"></div></body></html>'); $body = $doc->getElementById('x'); $div = $doc->getElementById('y'); $body->removeChild($div); $doc->getElementById('y'); // <div id="y">