1

Found a really weird problem with jQuery in IE7 today where it isn't finding selectors properly inside an element. Here's the HTML code:

<DIV id=firstVideoWrap>
    <OBJECT style="FLOAT: left" id=firstVideo width=300 height=300>
        <PARAM NAME="allowfullscreen" VALUE="true" />
        <PARAM NAME="movie" VALUE="http://vimeo.com/">
    </OBJECT>
</DIV>
<DIV id=secondVideoWrap>
    <OBJECT style="FLOAT: left" id=secondVideo width=300 height=300>
        <PARAM NAME="allowscriptaccess" VALUE="always" />
        <PARAM NAME="movie" VALUE=http://vimeo.com/moogaloop.swf />
        <PARAM NAME="wmode" VALUE="opaque" />
    </OBJECT>
</DIV>

and the relevant javascript:

console.log(jQuery("#firstVideo param").length);
console.log(jQuery("#firstVideoWrap param").length);
console.log(jQuery("#secondVideo param").length);
console.log(jQuery("#secondVideoWrap param").length);

It is giving the output:

5
2
5
3

Here it is in JSFiddle: http://jsfiddle.net/uGpUy/2/

It seems that IE isn't counting the number of param's on an object and instead is counting all param's on the entire page. While when I use the wrapping div it counts them correctly.

Also If I do:

jQuery("#secondVideo > param").length

It works correctly.

Is this a jQuery bug or something I've done wrong in my code?

EDIT: I've submitted a jQuery bug ticket for this: http://bugs.jquery.com/ticket/11646, will see how that progresses.


Even more, in IE8 all four lengths are 0. Using jQuery("#secondVideo > param") also yields 0... No idea why it happens.

4

2 に答える 2

1

It looks to be a bug related to the <OBJECT /> tag. If you replace your <OBJECT /> tags with <DIV /> tags, it works just as you intended:

2
2
3
3

I did get it to work by using .children() on the <OBJECT /> selectors:

console.log(jQuery("#firstVideo").children("param").length);
console.log(jQuery("#firstVideoWrap param").length);
console.log(jQuery("#secondVideo").children("param").length);
console.log(jQuery("#secondVideoWrap param").length);

Outputs:

2
2
3
3

Another Note:

The bug seems to be in the .find() method, as when I tried to use that instead of .children() it returned:

5
2
5
3
于 2012-04-25T15:37:14.873 に答える
0

さらに、IE8では4つの長さすべてが0です。使用jQuery("#secondVideo > param")すると0も生成されます...なぜそれが発生するのかわかりません。

于 2012-04-25T15:16:57.483 に答える