Opera and $$('.wrapper .class') seems not to work correctly

1 view
Skip to first unread message

Cyrus

unread,
Jan 12, 2009, 10:37:00 AM1/12/09
to Prototype & script.aculo.us
Hi there,

I have found a weird behaviour in the opera browser. I am not sure if
this is really a bug or an intended behaviour.

The following example shows that the $$ function only returns one
element instead of two. This is only because the second element is in
a different dom level. All other browser return two elements with this
example.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/
TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" xml:lang="de">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Test</title>

<script src="jsLib/prototype.js" type="text/javascript"></script>

<script type="text/javascript">
//<![CDATA[
function init() {
// init more information handling
var test = $$('.wrapper .class');
}

// when the dom is fully loaded, execute these scripts
document.observe("dom:loaded", init);
//]]>
</script>

</head>

<body>

<div class="wrapper">
<a href="#" class="class">test</a>
</div>
<div>
<div class="wrapper">
<a href="#" class="class">test</a>
</div>
</div>
</body>
</html>

kangax

unread,
Jan 12, 2009, 11:30:48 AM1/12/09
to Prototype & script.aculo.us
On Jan 12, 10:37 am, Cyrus <arianglan...@googlemail.com> wrote:
> Hi there,
>
> I have found a weird behaviour in the opera browser. I am not sure if
> this is really a bug or an intended behaviour.

[...]

Which versions of Prototype.js and Opera?

--
kangax

Cyrus

unread,
Jan 12, 2009, 12:27:14 PM1/12/09
to Prototype & script.aculo.us
Prototype 1.6.0.3
Opera 9.63

Alex Mcauley

unread,
Jan 13, 2009, 4:28:19 AM1/13/09
to prototype-s...@googlegroups.com
if its any help the same thing happens in google chrome !!

Richard Quadling

unread,
Jan 13, 2009, 4:41:22 AM1/13/09
to prototype-s...@googlegroups.com
2009/1/13 Alex Mcauley <webm...@thecarmarketplace.com>:
Adding ...

test.each(function(el){el.style.backgroundColor='green';});

to the script (just after the var test line) and I see 2 green divs.

Using Windows XP Pro SP3 with Chrome V1.0.154.43, Firefox V3.0.5 and
IE V7.0.5730.13.

NFF/Picnic?
--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

Cyrus

unread,
Jan 13, 2009, 4:52:28 AM1/13/09
to Prototype & script.aculo.us
Not in Opera 9.63 I am afraid ...

On 13 Jan., 10:41, "Richard Quadling" <rquadl...@googlemail.com>
wrote:
> 2009/1/13 Alex Mcauley <webmas...@thecarmarketplace.com>:

T.J. Crowder

unread,
Jan 13, 2009, 5:35:37 AM1/13/09
to Prototype & script.aculo.us
Hi,

> I am not sure if
> this is really a bug or an intended behaviour.

If you're getting back one element, not two, it's a bug. The question
is, in what -- Prototype's selection code, Opera, or both? I lean
toward Opera bug.

Interestingly, this _doesn't_ fail on Opera 9.10 for Windows: It
returns two elements as expected.

Have you tried it using a different classname than "class" for the
inner element? (I tend to think you just used that in your example,
having seen this in something else, but just in case...)
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

Cyrus

unread,
Jan 13, 2009, 6:26:19 AM1/13/09
to Prototype & script.aculo.us
I just used .class for this example. In my case I have a much more
complex HTML structure so it took me a while to actually find the bug.

> If you're getting back one element, not two, it's a bug. The question
> is, in what -- Prototype's selection code, Opera, or both? I lean
> toward Opera bug.

I guess the same, but maybe Prototype need an internal Opera
workarround here?

What would you suggest? File a bug report at Opera, Prototype or both?

kangax

unread,
Jan 13, 2009, 8:20:37 AM1/13/09
to Prototype & script.aculo.us
On Jan 13, 6:26 am, Cyrus <arianglan...@googlemail.com> wrote:

[...]

> What would you suggest? File a bug report at Opera, Prototype or both?

I can confirm this with 9.61 on Mac OSX. Here's a minimal failing test
case:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/
1.6.0.3/prototype.js" type="text/javascript"></script>
</head>
<body>
<div class="wrapper">
<a href="#" class="class">test</a>
</div>
<div>
<div class="wrapper">
<a href="#" class="class">test</a>
</div>
</div>
<script type="text/javascript">
document.write($$('.wrapper .class').length);
</script>
</body>
</html>

Should write "2" but writes "1".

This looks like an Opera bug. Moreover, I think we already have a
similar ticket filed (which was essentially due to a bug in Opera's
XPath engine bug and the way it handles descendant selectors). For
example, switching to "child" selector ('.wrapper > .class') returns
proper result - "2".

[...]

--
kangax

Cyrus

unread,
Jan 13, 2009, 8:23:51 AM1/13/09
to Prototype & script.aculo.us
Ok, thanks.

Unfortunately I cannot use the child selector in my case.

I'll write a bug report.

T.J. Crowder

unread,
Jan 13, 2009, 8:30:12 AM1/13/09
to Prototype & script.aculo.us
Hi Juriy,

That inline script could muddy the water in terms of DOM availability,
etc. Perhaps a minor mod:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/prototype/
1.6.0.3/prototype.js" type="text/javascript"></script>
<script type="text/javascript">
document.observe('dom:loaded', function() {
$('matchcount').update('Matches: ' + $$
('.wrapper .inner').length);
});
</script>
</head>
<body>
<div class="wrapper">
<a href="#" class="inner">test</a>
</div>
<div>
<div class="wrapper">
<a href="#" class="inner">test</a>
</div>
</div>
<div id='matchcount'></div>
</body>
</html>

I also changed "class" to "inner", again for clear water.

FWIW,

-- T.J.

Cyrus

unread,
Jan 13, 2009, 8:50:40 AM1/13/09
to Prototype & script.aculo.us

kangax

unread,
Jan 13, 2009, 9:17:04 AM1/13/09
to Prototype & script.aculo.us
On Jan 13, 8:30 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Hi Juriy,
>
> That inline script could muddy the water in terms of DOM availability,
> etc. Perhaps a minor mod:

I usually try to eliminate as much of irrelevant prototypeism as
possible when creating a testcase : ) Why use "dom:loaded" (which is
also known to be unreliable in IE in its current implementation) when
we can simply run script at the time when <body> is definitely loaded
and parsed.

[...]

--
kangax

T.J. Crowder

unread,
Jan 13, 2009, 12:58:41 PM1/13/09
to Prototype & script.aculo.us
> I usually try to eliminate as much of irrelevant prototypeism as
> possible when creating a testcase : )

Fair 'nuff, but I'd still use something other than inline to allow for
browsers being difficult about the closing body tag and DOM rendering
time. Probably me being paranoid. Perhaps (shock and horror) DOM0
window.onload stuff, image loading not being an issue:

<script type='text/javascript'>
window.onload = function() {
alert('Found ' + $$('.wrapper .inner').length);
});
</script>

> at the time when <body> is definitely loaded
> and parsed.

Is it, definitely? Within the tag? (Serious question, you know more
about this stuff than I do.)

-- T.J. ;-)

kangax

unread,
Jan 13, 2009, 1:48:53 PM1/13/09
to Prototype & script.aculo.us
On Jan 13, 12:58 pm, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> > I usually try to eliminate as much of irrelevant prototypeism as
> > possible when creating a testcase : )
>
> Fair 'nuff, but I'd still use something other than inline to allow for
> browsers being difficult about the closing body tag and DOM rendering
> time. Probably me being paranoid. Perhaps (shock and horror) DOM0
> window.onload stuff, image loading not being an issue:
>
> <script type='text/javascript'>
> window.onload = function() {
> alert('Found ' + $$('.wrapper .inner').length);});
>
> </script>

This is perfectly fine of course : )

>
> > at the time when <body> is definitely loaded
> > and parsed.
>
> Is it, definitely? Within the tag? (Serious question, you know more
> about this stuff than I do.)

AFAIK, <script> elements are loaded and parsed sequentially (just like
most if not all other elements - exception being, maybe, <meta> tag
which has "Content-Type" and so might be parsed as early as
possible).

When a <script> element (the one before closing </body> tag) is
downloaded, parsed and evaluated, all of the DOM elements before it
should be present in DOM (that includes <body> of course)

I'm far from an expert in this field, but am pretty sure this is
what's happening : )

[...]

--
kangax

Jerod Venema

unread,
Jan 13, 2009, 4:43:17 PM1/13/09
to prototype-s...@googlegroups.com
Hey all, when you're replying to these threads, can you make sure you keep it on-list? I like to keep up with various solutions to all these problems, and seeing half the solution (or no solution at all) is really frustrating.

(@Kangax, I know I've seen a few replies to messages you've sent off-list, and since I know you've got good replies, I'd love it if they'd stay on the list. :-D)

Thanks!
--
Jerod Venema
Frozen Mountain Software
http://www.frozenmountain.com/
919-368-5105
Reply all
Reply to author
Forward
0 new messages