]> source.dussan.org Git - jquery.git/commitdiff
Traversing: Fix `contents()` on `<object>`s with children
authorPat O'Callaghan <patocallaghan@gmail.com>
Mon, 6 May 2019 17:23:00 +0000 (18:23 +0100)
committerMichał Gołębiowski-Owczarek <m.goleb@gmail.com>
Mon, 6 May 2019 17:23:00 +0000 (19:23 +0200)
Fixes gh-4384
Closes gh-4385

src/traversing.js
test/unit/traversing.js

index 18b964a49078a637fc006e3a1b056923a3b48c64..a91183b289d27fa7b3655696b64d4d212b498258 100644 (file)
@@ -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;
                }
 
index e70c121edf8e8d99c90dd6d826e28aaecd91acfa..e8d23536ef955e3aaafb3b47a3795ca07a640cdc 100644 (file)
@@ -808,6 +808,19 @@ QUnit.test( "contents() for <object />", function( assert ) {
        jQuery( "#qunit-fixture" ).append( svgObject );
 } );
 
+QUnit.test( "contents() for <object /> with children", function( assert ) {
+       assert.expect( 1 );
+
+       var object = "<object type='application/x-shockwave-flash' width='200' height='300' id='penguin'>" +
+               "<param name='movie' value='flash/penguin.swf'>" +
+               "<param name='quality' value='high'>" +
+               "<img src='images/penguin.jpg' width='200' height='300' alt='Penguin'>" +
+       "</object>";
+
+       var contents = jQuery( object ).contents();
+       assert.equal( contents.length, 3, "Check object contents children are correct" );
+} );
+
 QUnit.test( "contents() for <frame />", function( assert ) {
        assert.expect( 2 );