javascript

Creating extension method for jquery

A brief technical note outlining the basic approach and applicable steps for creating extension methods for jquery.

To create your own custom methods for jQuery, you can write a function as follows:

jQuery.fn.icerik = function (options) {
            var defaultSettings = {
                 etiket:"Test Metni"
                },

            var options1= jQuery.extend({}, defaultSettings, options);

            alert(options1.etiket + " : " jQuery(this).text());
        }

Usage:

jQuery("#testDiv").icerik();


Note: If you use it as “jQuery.fn.functionName”, it will be called after the selector (jQuery(“#testDiv”).functionName()), if you use it as jQuery.functionName, it will be called directly as jQuery.functionName().