From 4d865d96aa5aae91823c50020b5c19da79566811 Mon Sep 17 00:00:00 2001 From: Pat O'Callaghan Date: Mon, 6 May 2019 18:23:00 +0100 Subject: [PATCH] Traversing: Fix `contents()` on ``s with children Fixes gh-4384 Closes gh-4385 --- src/traversing.js | 2 +- test/unit/traversing.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/traversing.js b/src/traversing.js index 18b964a49..a91183b28 100644 --- a/src/traversing.js +++ b/src/traversing.js @@ -145,7 +145,7 @@ jQuery.each( { return siblings( elem.firstChild ); }, contents: function( elem ) { - if ( typeof elem.contentDocument !== "undefined" ) { + if ( elem.contentDocument != null ) { return elem.contentDocument; } diff --git a/test/unit/traversing.js b/test/unit/traversing.js index e70c121ed..e8d23536e 100644 --- a/test/unit/traversing.js +++ b/test/unit/traversing.js @@ -808,6 +808,19 @@ QUnit.test( "contents() for ", function( assert ) { jQuery( "#qunit-fixture" ).append( svgObject ); } ); +QUnit.test( "contents() for with children", function( assert ) { + assert.expect( 1 ); + + var object = "" + + "" + + "" + + "Penguin" + + ""; + + var contents = jQuery( object ).contents(); + assert.equal( contents.length, 3, "Check object contents children are correct" ); +} ); + QUnit.test( "contents() for ", function( assert ) { assert.expect( 2 );