mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Manipulation: Support $el.html(selfRemovingScript) (#5378)
Don't try to remove a script element that has already removed itself. Also, compress `DOMEval.js`. Fixes gh-5377 Closes gh-5378
This commit is contained in:
parent
e8b7db4b0f
commit
937923d9ee
@ -14,12 +14,13 @@ export function DOMEval( code, node, doc ) {
|
||||
script = doc.createElement( "script" );
|
||||
|
||||
script.text = code;
|
||||
if ( node ) {
|
||||
for ( i in preservedScriptAttributes ) {
|
||||
if ( node[ i ] ) {
|
||||
script[ i ] = node[ i ];
|
||||
}
|
||||
for ( i in preservedScriptAttributes ) {
|
||||
if ( node && node[ i ] ) {
|
||||
script[ i ] = node[ i ];
|
||||
}
|
||||
}
|
||||
doc.head.appendChild( script ).parentNode.removeChild( script );
|
||||
|
||||
if ( doc.head.appendChild( script ).parentNode ) {
|
||||
script.parentNode.removeChild( script );
|
||||
}
|
||||
}
|
||||
|
@ -1819,6 +1819,21 @@ QUnit.test( "html(script nomodule)", function( assert ) {
|
||||
}, 1000 );
|
||||
} );
|
||||
|
||||
QUnit.test( "html(self-removing script) (gh-5377)", function( assert ) {
|
||||
assert.expect( 2 );
|
||||
|
||||
var $fixture = jQuery( "#qunit-fixture" );
|
||||
|
||||
$fixture.html(
|
||||
[
|
||||
"<script>document.currentScript.parentNode.removeChild( document.currentScript ); QUnit.assert.ok( true, 'removed document.currentScript' );</script>",
|
||||
"<div>",
|
||||
"<script>document.currentScript.parentNode.removeChild( document.currentScript ); QUnit.assert.ok( true, 'removed inner document.currentScript' );</script>",
|
||||
"</div>"
|
||||
].join( "" )
|
||||
);
|
||||
} );
|
||||
|
||||
QUnit.test( "html(Function) with incoming value -- direct selection", function( assert ) {
|
||||
|
||||
assert.expect( 4 );
|
||||
|
Loading…
Reference in New Issue
Block a user