Skip to content

Commit 2fea569

Browse files
author
Jack Bates
committed
Handle .innerHTML exception with DOMParser(), fixes jquery#5022
1 parent 4a64f9a commit 2fea569

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/manipulation.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,13 @@ jQuery.extend({
486486
div = context.createElement("div");
487487

488488
// Go to html and back, then peel off extra wrappers
489-
div.innerHTML = wrap[1] + elem + wrap[2];
489+
try {
490+
div.innerHTML = wrap[1] + elem + wrap[2];
491+
} catch(e) {
492+
493+
// .innerHTML throws exception in non-HTML documents, #5022
494+
div.appendChild(new DOMParser().parseFromString(wrap[1] + elem + wrap[2], context.contentType).documentElement);
495+
}
490496

491497
// Move to the right depth
492498
while ( depth-- ) {

0 commit comments

Comments
 (0)