Miguel Ping
Miguel Ping

Reputation: 18347

Migrating from prototype to jquery

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

Answers (2)

Simon David Pratt
Simon David Pratt

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

Joel Mueller
Joel Mueller

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

Related Questions