Description
Version: jQuery 3.4.1
Since 0ba8e38 it appears that using contents() to get the children of an <object> is not working as expected.
Taking this example HTML
<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>
I'd expect the following to happen
jQuery(objectHtml).contents().length // => 3
But what actually happens is:
jQuery(objectHtml).contents().length // => 0
This happens because on this line
|
if ( typeof elem.contentDocument !== "undefined" ) { |
|
return elem.contentDocument; |
it only checks if
elem.contentDocument is not
undefined. But in this scenario
elem.contentDocument is
null so the conditional is truthy and enters the
if block and returns
null for the contents.
If we change the conditional to be elem.contentDocument != null it works correctly.
Link to test case
https://codepen.io/patocallaghan/pen/bybaWv?editors=0011
I have a PR to fix it but I wanted to open an issue first.
Description
Version: jQuery 3.4.1
Since 0ba8e38 it appears that using
contents()to get the children of an<object>is not working as expected.Taking this example HTML
I'd expect the following to happen
But what actually happens is:
This happens because on this line
jquery/src/traversing.js
Lines 148 to 149 in 110802c
elem.contentDocumentis notundefined. But in this scenarioelem.contentDocumentisnullso the conditional is truthy and enters theifblock and returnsnullfor the contents.If we change the conditional to be
elem.contentDocument != nullit works correctly.Link to test case
https://codepen.io/patocallaghan/pen/bybaWv?editors=0011
I have a PR to fix it but I wanted to open an issue first.