Mask Mask - 4 months ago 9
jQuery Question

How to add a function to jQuery?

What's the easiest way to define a new jQuery member function?

So that I can call something like:

$('#id').applyMyOwnFunc()

Answer

Please see Defining your own functions in jQuery:

In this post i want to present how easy define your own functions in jQuery and using them.

From the post:

jQuery.fn.yourfunctionname = function() {
    var o = $(this[0]) // It's your element

    return this; // This is needed so others can keep chaining off of this
};

Used:

$(element).yourfunctionname()