Skip to content

Commit 0e12350

Browse files
authored
Core: Switch $.parseHTML from document.implementation to DOMParser
Using a document created via: ```js document.implementation.createHTMLDocument( "" ) ``` was needed in IE 9 which doesn't support `DOMParser#parseFromString` for `text/html`. We can switch to: ```js ( new window.DOMParser() ) .parseFromString( "", "text/html" ) ``` now, saving some bytes. Closes jquerygh-5572
1 parent 75b48e6 commit 0e12350

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

src/core/parseHTML.js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { jQuery } from "../core.js";
2-
import { document } from "../var/document.js";
32
import { rsingleTag } from "./var/rsingleTag.js";
43
import { buildFragment } from "../manipulation/buildFragment.js";
54
import { isObviousHtml } from "./isObviousHtml.js";
@@ -17,20 +16,14 @@ jQuery.parseHTML = function( data, context, keepScripts ) {
1716
context = false;
1817
}
1918

20-
var base, parsed, scripts;
19+
var parsed, scripts;
2120

2221
if ( !context ) {
2322

2423
// Stop scripts or inline event handlers from being executed immediately
25-
// by using document.implementation
26-
context = document.implementation.createHTMLDocument( "" );
27-
28-
// Set the base href for the created document
29-
// so any parsed elements with URLs
30-
// are based on the document's URL (gh-2965)
31-
base = context.createElement( "base" );
32-
base.href = document.location.href;
33-
context.head.appendChild( base );
24+
// by using DOMParser
25+
context = ( new window.DOMParser() )
26+
.parseFromString( "", "text/html" );
3427
}
3528

3629
parsed = rsingleTag.exec( data );

0 commit comments

Comments
 (0)