Reputation: 18347
I am migrating my js lib from prototype to jquery. However, I don't know how to replace the following code:
var utilityMethods = {
autoHide : function(element) {
//...
}
Element.addMethods('SPAN', utilityMethods);
Is there a jQuery equivalent for extending the DOM?
Thanks
Upvotes: 2
Views: 1245
Reputation: 476
You extend JQuery objects like so:
var utilityMethods = {
autoHide : function(element) {
//...
}
};
jQuery.fn.extend(utilityMethods);
More info: http://docs.jquery.com/Core/jQuery.extend
Upvotes: 3
Reputation: 28765
Actually, jQuery specifically avoids extending the DOM. Having recently completed a migration from Prototype to jQuery, this was one of the selling points for me. Instead, you extend jQuery itself. Selecting a DOM object with jQuery gives you a jQuery object that contains a reference to one or more DOM objects. Any method calls on the jQuery object (including your custom utility methods) operate on the DOM elements referenced by that jQuery object.
Upvotes: 1