Reputation: 7368
I have a site with both jQuery 1.8 and Prototype 2, using $ (dollar sign) seems to call jQuery but I want to invoke Prototype (from console). Specifically to do something like this: How to find event listeners on a DOM node when debugging or from the JavaScript code?
Ise there an Equivalent in Prototype like the jQuery() function?
Upvotes: 0
Views: 599
Reputation: 31644
Prototype is not a single object like jQuery, so you cannot invoke it like that.
var jq = $('#id')
At this point you have a jQuery object that is referencing a DOM. If you try to use it like an actual DOM object, however, it won't work.
// This won't work
jq.className = "";
// This works because it's referencing the function inside jQuery
jq.removeClass();
Please note that jQuery can give you the actual DOM element if you need it, but this is not the default behavior.
You need to think of Prototype as making base Javascript better as opposed to an object. A great example is Object.isUndefined. The Object
object already exists in Javascript, Prototype is simply extending it with another function. When you see Prototype behaving like jQuery, it's almost always because Prototype extended what was already there
// This is a DOM reference
var pro = $('id'); // equivalent to document.getElementById('id');
pro.className = "";
// But there's no base Prototype object so this fails
pro.isUndefined();
// This is correct
Object.isUndefined(pro);
Upvotes: 1