From 3e3b09d68d317a3fe567e377e9032319ac5e0829 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E5=8D=97=E6=BC=82=E4=B8=80=E5=8D=92?= Date: Mon, 30 Jan 2017 06:32:15 +0800 Subject: [PATCH] Traversing: $.fn.contents() supports HTMLTemplateElement Fixes gh-3436 Closes gh-3462 --- src/traversing.js | 13 ++++++++++- test/unit/traversing.js | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/traversing.js b/src/traversing.js index 50cd2d6ee..d96869017 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -143,7 +143,18 @@ jQuery.each( { return siblings( elem.firstChild ); }, contents: function( elem ) { - return elem.contentDocument || jQuery.merge( [], elem.childNodes ); + if ( jQuery.nodeName( elem, "iframe" ) ) { + return elem.contentDocument; + } + + // Support: IE 9 - 11 only, iOS 7 only, Android Browser <=4.3 only + // Treat the template element as a regular one in browsers that + // don't support it. + if ( jQuery.nodeName( elem, "template" ) ) { + elem = elem.content || elem; + } + + return jQuery.merge( [], elem.childNodes ); } }, function( name, fn ) { jQuery.fn[ name ] = function( until, selector ) { diff --git a/test/unit/traversing.js b/test/unit/traversing.js index c7ed01415..83c267a27 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -743,6 +743,58 @@ QUnit.test( "contents()", function( assert ) { assert.equal( c[ 0 ].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); } ); +QUnit.test( "contents() for