5 "../manipulation/buildFragment",
7 // This is the only module that needs core/support
9 ], function( jQuery, document, rsingleTag, buildFragment, support ) {
13 // Argument "data" should be string of html
14 // context (optional): If specified, the fragment will be created in this context,
15 // defaults to document
16 // keepScripts (optional): If true, will include scripts passed in the html string
17 jQuery.parseHTML = function( data, context, keepScripts ) {
18 if ( typeof data !== "string" ) {
21 if ( typeof context === "boolean" ) {
22 keepScripts = context;
26 var base, parsed, scripts;
30 // Stop scripts or inline event handlers from being executed immediately
31 // by using document.implementation
32 if ( support.createHTMLDocument ) {
33 context = document.implementation.createHTMLDocument( "" );
35 // Set the base href for the created document
36 // so any parsed elements with URLs
37 // are based on the document's URL (gh-2965)
38 base = context.createElement( "base" );
39 base.href = document.location.href;
40 context.head.appendChild( base );
46 parsed = rsingleTag.exec( data );
47 scripts = !keepScripts && [];
51 return [ context.createElement( parsed[ 1 ] ) ];
54 parsed = buildFragment( [ data ], context, scripts );
56 if ( scripts && scripts.length ) {
57 jQuery( scripts ).remove();
60 return jQuery.merge( [], parsed.childNodes );
63 return jQuery.parseHTML;