From: 南漂一卒 Date: Sun, 29 Jan 2017 22:32:15 +0000 (+0800) Subject: Traversing: $.fn.contents() supports HTMLTemplateElement X-Git-Tag: 3.2.0~16 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F3530%2Fhead;p=jquery.git Traversing: $.fn.contents() supports HTMLTemplateElement Fixes gh-3436 Closes gh-3462 --- 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