From: Richard Gibson Date: Mon, 8 Jan 2024 17:30:39 +0000 (-0500) Subject: Manipulation: Support $el.html(selfRemovingScript) X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cbc15c9c31fa855304b4b63c13a0c8fb0ef61275;p=jquery.git Manipulation: Support $el.html(selfRemovingScript) Don't try to remove a script element that has already removed itself. Fixes gh-5377 Closes gh-5378 (cherry-picked from commit 937923d9ee8dfd19008447b5059cbd13ee5a23ac) --- diff --git a/src/core/DOMEval.js b/src/core/DOMEval.js index 59f6e0247..e3ecd60ac 100644 --- a/src/core/DOMEval.js +++ b/src/core/DOMEval.js @@ -36,7 +36,9 @@ define( [ } } } - doc.head.appendChild( script ).parentNode.removeChild( script ); + if ( doc.head.appendChild( script ).parentNode ) { + script.parentNode.removeChild( script ); + } } return DOMEval; diff --git a/test/unit/manipulation.js b/test/unit/manipulation.js index 975813e34..f894cc626 100644 --- a/test/unit/manipulation.js +++ b/test/unit/manipulation.js @@ -1871,6 +1871,21 @@ QUnit[ }, 1000 ); } ); +QUnit.test( "html(self-removing script) (gh-5377)", function( assert ) { + assert.expect( 2 ); + + var $fixture = jQuery( "#qunit-fixture" ); + + $fixture.html( + [ + "", + "
", + "", + "
" + ].join( "" ) + ); +} ); + QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) { assert.expect( 4 );