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