Here is some sample code which works in all browsers I've tested, but
errors in Opera:
<html>
<head>
<title>Opera test</title>
<script src="prototype.js" type="text/javascript"></script>
<script type="text/javascript">
Element.addMethods("DIV", {
divOperaTest: function(e) { window.alert("Test Successful (" +
e.innerHTML + ")"); }
});
document.observe("contentloaded", function() {
$$("div").each(function(a){ a.divOperaTest(); });
});
</script>
</head>
<body>
<div>Test Div</div>
<div>Test Div 2</div>
</body>
</html>
Changing the line which reads:
$$("div").each(function(a){ a.divOperaTest(); });
to read:
$$("div").each(function(a){ $(a).divOperaTest(); });
Makes it work just fine...but I'm wondering why it's
necessary...doesn't each() pass in the extended element already (and
the $$() should definitely be extended already as well)...
I don't know if this is a bug in Opera, in Prototype, or in my own
logic...I'm willing to accept that it is any (or all) of the above.
For now, I can just do $() around my divs...though I would like to
understand the reasoning why...
Here is the error console from within Opera (btw - this is the
prototype 1.6 pre-release)
Event thread: dataavailable
Error:
name: TypeError
message: Statement on line 6: Type mismatch (usually a non-object
value used where an object is required)
Backtrace:
Line 6 of inline#1 script in file://users/ntoone/test.html
a.divOperaTest();
Line 584 of linked script file://users/ntoone/prototype.js
iterator(value, index++);
Line 831 of linked script file://users/ntoone/prototype.js
iterator(this[i]);
Line 585 of linked script file://users/ntoone/prototype.js
this._each((function (value)
{
iterator(value, index++);
}
));
Line 6 of inline#1 script in file://users/ntoone/test.html
$$("div").each((function (a)
{
a.divOperaTest();
}
));
Line 3867 of linked script file://users/ntoone/prototype.js
handler.call(event.target, event);
At unknown location
[statement source code not available]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---