{"id":1111,"date":"2014-10-20T15:00:27","date_gmt":"2014-10-20T12:00:27","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=1111"},"modified":"2014-11-07T17:07:16","modified_gmt":"2014-11-07T15:07:16","slug":"things-i-learned-creating-a-jquery-plugin-part-ii","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/","title":{"rendered":"Things I learned creating a jQuery Plugin (Part II)"},"content":{"rendered":"<p>This post is the continuation of the series\u00a0<a title=\"Things I learnt creating a jQuery Plugin (Part I)\" href=\"http:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/\">Things I learned creating a jQuery Plugin<\/a>.<\/p>\n<p>In the first part we have seen how the structure of a jQuery plugin must be, the plugin entry point (so called wrapper function) and how we can control the\u00a0behavior\u00a0of a method as a getter or setter.<\/p>\n<h2>Define default options<\/h2>\n<p>Your plugin more probably will accept different set of options to allow some configuration. For these reason it is important to define a set of default options which will be applied in cases where no options are specified by the user. Place it within the jQuery wrapper function is a good practice:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/\r\n\/\/ Default options\r\n\/\/\r\n$.fn&#x5B;pluginName].defaults = {\r\n    opt_A: &quot;&quot;\r\n}; <\/pre>\n<h2>Encapsulate your plugin code<\/h2>\n<p>A good practice is to encapsulate the logic of our plugin within a function, this way our plugin\u2019s entry point function can easily initialize or call the right method.<\/p>\n<p>For example, in a really simple wrapper function, that simply initializes a plugin\u2019s instance on each selected element, we could write something like:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$.fn&#x5B;pluginName] = function(options) {\r\n    return this.each(function() {\r\n        new Plugin(this, options);\r\n    });\r\n} <\/pre>\n<h3>The plugin constructor<\/h3>\n<p>The main part of your plugin is the constructor function. Usually this function is responsible to initialize the plugin, store a reference to the selected element or merge the passed options with the default ones:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nfunction Plugin(element, options) {\r\n    \/\/ Store references to the selected element\r\n    this.el = element;\r\n    this.$el = $(element);\r\n\r\n    \/\/ Merge passes options with defaults\r\n    this.options = $.extend({}, $.fn&#x5B;pluginName].defaults, options);\r\n\r\n    \/\/ ...other code here...\r\n\r\n    \/\/ Initialize the plugin instance\r\n    this.init();\r\n} <\/pre>\n<h3>Prototype your plugin<\/h3>\n<p>Once the <code>Plugin<\/code> function is defined we can modify its prototype adding all the desired methods we want for our plugin.<\/p>\n<p>There are a couple of methods are a good practice to implement:<\/p>\n<ul>\n<li>A <code>init<\/code> method, which initializes each plugins instance: creating new DOM elements, registering listeners, etc<\/li>\n<li>A <code>destroy<\/code> method, responsible to free any resource used by the plugin: extra elements, unregister listeners, etc.<\/li>\n<\/ul>\n<p>Other methods can be created within your plugin\u2019s prototype but remember the convention: <em>Use method names starting with underscore for those methods we want to be private<\/em>.<\/p>\n<blockquote><p><span style=\"color: #339966;\">If you remember the first part of this series, what really happens is when you call a plugin\u2019s method, the wrapper function of our plugin checks if the method\u2019s name starts with underscore and if so then avoids the call.<\/span><\/p><\/blockquote>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/\r\n\/\/ Plugin prototype\r\n\/\/\r\nPlugin.prototype = {\r\n\r\n    \/\/\r\n    \/\/ Initialize the plugin instance\r\n    \/\/\r\n    init: function() {\r\n        ...\r\n    },\r\n\r\n    \/\/\r\n    \/\/ Free resources\r\n    \/\/\r\n    destroy: function() {\r\n        ...\r\n    },\r\n\r\n    \/\/\r\n    \/\/ Public method\r\n    \/\/\r\n    publicMethod: function() {\r\n        ...\r\n    },\r\n\r\n    \/\/\r\n    \/\/ Private method (it starts with an underscore)\r\n    \/\/\r\n    _privateMethod: function() {\r\n        ...\r\n    }\r\n\r\n} <\/pre>\n<h3>A note on the <code>destroy<\/code> method<\/h3>\n<p>As we have commented, the <code>destroy<\/code> method must free any resource used by the plugin instance, like extra created elements, unregister listeners, etc<\/p>\n<p>If you remember the first article, you will notice that the plugin\u2019s instance is stored within the selected DOM element where the plugin is applied:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$.fn&#x5B;pluginName] = function(options) {\r\n    var args = arguments;\r\n\r\n    if (options === undefined || typeof options === 'object') {\r\n        \/\/ Creates a new plugin instance, for each selected element, and\r\n        \/\/ stores a reference withint the element's data\r\n        return this.each(function() {\r\n            if (!$.data(this, 'plugin_' + pluginName)) {\r\n                $.data(this, 'plugin_' + pluginName, new Plugin(this, options));\r\n            }\r\n        });\r\n    } \r\n\r\n    ...\r\n}; <\/pre>\n<p>That occurs in the line:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$.data(this, 'plugin_' + pluginName, new Plugin(this, options)); <\/pre>\n<p>So, the last action in your <code>destroy<\/code> method must be always remove the plugin\u2019s instance reference from the element\u2019s data. This can easily done using the reference to the DOM element stored in the plugin instance:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/\r\n\/\/ Free resources\r\n\/\/\r\ndestroy: function() {\r\n\r\n    \/\/ Remove elements, unregister listerners, etc\r\n\r\n    \/\/ Remove data\r\n    this.$el.removeData();\r\n} <\/pre>\n<h2>Allow the use of callbacks in our plugin<\/h2>\n<p>It is common jQuery plugins allows to register callback functions to be called when an event or action is generated by the plugins. For example, in the <a href=\"http:\/\/acuriousanimal.com\/code\/tagger\/\" target=\"_blank\">tagger<\/a> plugin the user can be notified when a new tag is added, removed, clicked, etc.<\/p>\n<p>Next lines shows the initialization of the tagger plugin setting the parameter<code>fieldSeparator<\/code> to a value different from the default options value and registering a callback function for the <code>onTagAdded<\/code> event:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#inputID').tagger({\r\n  fieldSeparator: '|'\r\n  onTagsAdded: function(tags) {\r\n    console.log('Added new tag: '+tags+'\\n');\r\n  }\r\n}); <\/pre>\n<p>To achieve this we need to make to main steps:<\/p>\n<ol>\n<li>Define a default and empty callback function in the plugins default options.<\/li>\n<li>At some place of our plugin\u2019s code make a call to the callback function.<\/li>\n<\/ol>\n<p>Continuing with the sample of the <a href=\"http:\/\/acuriousanimal.com\/code\/tagger\/\" target=\"_blank\">tagger<\/a> plugin, its default options looks like:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/\r\n\/\/ Default options\r\n\/\/\r\n$.fn&#x5B;pluginName].defaults = {\r\n    fieldSeparator: &quot;,&quot;,\r\n    readOnly: false,\r\n    \/\/ Callback invoked when user calls the 'tags' method\r\n    onTagsAdded: function() {\r\n    },\r\n    \/\/ Callback invoked when user calls the 'remove' method\r\n    onTagsRemoved: function() {\r\n    },\r\n    \/\/ Callback invoked when user calls the 'clear' method.\r\n    \/\/ Note: Internally the 'clear' method uses the 'remove'.\r\n    onClear: function() {\r\n    },\r\n    \/\/ Callback invoked when the user click a tag label\r\n    onClick: function() {\r\n    }\r\n}; <\/pre>\n<p>Later, in the method responsible to add new tags to the tag list, a call is made to the<code>onTagsAdded<\/code> function:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n\/\/ Adds one or more tags\r\n\/\/ ...\r\n\/\/\r\ntags: function(tags) {\r\n      ...\r\n      \/\/ Call the callback\r\n      this.options.onTagsAdded.call(this, tags);\r\n      ...\r\n    }\r\n}, <\/pre>\n<blockquote><p><span style=\"color: #339966;\">Note how we have forced to set the<code>this<\/code> object and passed the value of the new added tag to the callback function.<\/span><\/p><\/blockquote>\n<h2>Summary<\/h2>\n<p>Ok, this is the end. A short series of two articles to introduce the main concepts to creating jQuery plugins isn\u2019t a bad thing when you are looking for help starting with jQuery and custom plugin development.<\/p>\n<p>Let\u2019s try to summarize the main points we have seen in this couple of posts:<\/p>\n<ul>\n<li>Understand the importance of entry point to your plugin. This is handled in a new function on the <code>$.fn<\/code> object and is responsible to (or can) control: plugin initialization, call to setter or getter methods, simulate private methods, etc.<\/li>\n<li>Encapsulate your plugin\u2019s functionalities in a prototyped function<\/li>\n<li>Store, if needed, a reference to the DOM element where your plugin is applied to.<\/li>\n<li>Remember to implement a <code>destroy<\/code> method responsible to free all the resources used by your plugin<\/li>\n<li>Create a default options object that serves as a base to extend it with the options specified by the user<\/li>\n<li>Keep calm and remember try and error is a (necessary) way to learn<\/li>\n<\/ul>\n<h2>References<\/h2>\n<p>The web is plenty of great information:<\/p>\n<ol>\n<li><a href=\"http:\/\/docs.jquery.com\/Plugins\/Authoring\" target=\"_blank\">http:\/\/docs.jquery.com\/Plugins\/Authoring<\/a><\/li>\n<li><a href=\"http:\/\/www.websanova.com\/tutorials\/jquery\/the-ultimate-guide-to-writing-jquery-plugins\" target=\"_blank\">http:\/\/www.websanova.com\/tutorials\/jquery\/the-ultimate-guide-to-writing-jquery-plugins<\/a><\/li>\n<li><a href=\"http:\/\/jqueryboilerplate.com\/\" target=\"_blank\">http:\/\/jqueryboilerplate.com\/<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/zenorocha\/jquery-plugin-patterns\" target=\"_blank\">https:\/\/github.com\/zenorocha\/jquery-plugin-patterns<\/a><\/li>\n<li><a href=\"http:\/\/coding.smashingmagazine.com\/2011\/10\/11\/essential-jquery-plugin-patterns\/\" target=\"_blank\">http:\/\/coding.smashingmagazine.com\/2011\/10\/11\/essential-jquery-plugin-patterns\/<\/a><\/li>\n<li><a href=\"http:\/\/addyosmani.com\/resources\/essentialjsdesignpatterns\/book\/#jquerypluginpatterns\" target=\"_blank\">http:\/\/addyosmani.com\/resources\/essentialjsdesignpatterns\/book\/#jquerypluginpatterns<\/a><\/li>\n<\/ol>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td><span class=\"reference\">Reference: <\/span><\/td>\n<td><a href=\"http:\/\/acuriousanimal.com\/blog\/2013\/02\/25\/things-i-learned-creating-a-jquery-plugin-part-ii\/\">Things I learned creating a jQuery Plugin (Part II)<\/a> from our <a href=\"http:\/\/www.webcodegeeks.com\/wcg\/\">WCG partner<\/a> Antonio Santiago at the <a href=\"http:\/\/acuriousanimal.com\/blog\/\">A Curious Animal<\/a> blog.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This post is the continuation of the series\u00a0Things I learned creating a jQuery Plugin. In the first part we have seen how the structure of a jQuery plugin must be, the plugin entry point (so called wrapper function) and how we can control the\u00a0behavior\u00a0of a method as a getter or setter. Define default options Your &hellip;<\/p>\n","protected":false},"author":7,"featured_media":919,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-1111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jquery"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Things I learned creating a jQuery Plugin (Part II) - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"This post is the continuation of the series\u00a0Things I learned creating a jQuery Plugin. In the first part we have seen how the structure of a jQuery plugin\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Things I learned creating a jQuery Plugin (Part II) - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"This post is the continuation of the series\u00a0Things I learned creating a jQuery Plugin. In the first part we have seen how the structure of a jQuery plugin\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2014-10-20T12:00:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-11-07T15:07:16+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Antonio Santiago\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Antonio Santiago\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/\"},\"author\":{\"name\":\"Antonio Santiago\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b9ad428a9312fc720bef9ebc43421e78\"},\"headline\":\"Things I learned creating a jQuery Plugin (Part II)\",\"datePublished\":\"2014-10-20T12:00:27+00:00\",\"dateModified\":\"2014-11-07T15:07:16+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/\"},\"wordCount\":1108,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"articleSection\":[\"jQuery\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/\",\"name\":\"Things I learned creating a jQuery Plugin (Part II) - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"datePublished\":\"2014-10-20T12:00:27+00:00\",\"dateModified\":\"2014-11-07T15:07:16+00:00\",\"description\":\"This post is the continuation of the series\u00a0Things I learned creating a jQuery Plugin. In the first part we have seen how the structure of a jQuery plugin\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"jQuery\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/javascript\/jquery\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Things I learned creating a jQuery Plugin (Part II)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b9ad428a9312fc720bef9ebc43421e78\",\"name\":\"Antonio Santiago\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/a6e48b7e3c6ccbf7b291a6d36f49b911f5472c409294e52ccd3d017e3faf4c2b?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/a6e48b7e3c6ccbf7b291a6d36f49b911f5472c409294e52ccd3d017e3faf4c2b?s=96&d=mm&r=g\",\"caption\":\"Antonio Santiago\"},\"description\":\"A Computer Science as profession and hobby. Firm believer of Software Engineering and a lover of Agile methodologies. There is no ring to rule them all, every place needs to forge its own master ring. His main field of experience is the Java ecosystem, and he has also worked actively with many related web technologies while looking to improve the client side of web applications.\",\"sameAs\":[\"http:\/\/acuriousanimal.com\/blog\/\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/antonio-santiago\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Things I learned creating a jQuery Plugin (Part II) - Web Code Geeks - 2026","description":"This post is the continuation of the series\u00a0Things I learned creating a jQuery Plugin. In the first part we have seen how the structure of a jQuery plugin","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/","og_locale":"en_US","og_type":"article","og_title":"Things I learned creating a jQuery Plugin (Part II) - Web Code Geeks - 2026","og_description":"This post is the continuation of the series\u00a0Things I learned creating a jQuery Plugin. In the first part we have seen how the structure of a jQuery plugin","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2014-10-20T12:00:27+00:00","article_modified_time":"2014-11-07T15:07:16+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","type":"image\/jpeg"}],"author":"Antonio Santiago","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Antonio Santiago","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/"},"author":{"name":"Antonio Santiago","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b9ad428a9312fc720bef9ebc43421e78"},"headline":"Things I learned creating a jQuery Plugin (Part II)","datePublished":"2014-10-20T12:00:27+00:00","dateModified":"2014-11-07T15:07:16+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/"},"wordCount":1108,"commentCount":1,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","articleSection":["jQuery"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/","name":"Things I learned creating a jQuery Plugin (Part II) - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","datePublished":"2014-10-20T12:00:27+00:00","dateModified":"2014-11-07T15:07:16+00:00","description":"This post is the continuation of the series\u00a0Things I learned creating a jQuery Plugin. In the first part we have seen how the structure of a jQuery plugin","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learned-creating-a-jquery-plugin-part-ii\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/"},{"@type":"ListItem","position":3,"name":"jQuery","item":"https:\/\/www.webcodegeeks.com\/category\/javascript\/jquery\/"},{"@type":"ListItem","position":4,"name":"Things I learned creating a jQuery Plugin (Part II)"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b9ad428a9312fc720bef9ebc43421e78","name":"Antonio Santiago","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/a6e48b7e3c6ccbf7b291a6d36f49b911f5472c409294e52ccd3d017e3faf4c2b?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/a6e48b7e3c6ccbf7b291a6d36f49b911f5472c409294e52ccd3d017e3faf4c2b?s=96&d=mm&r=g","caption":"Antonio Santiago"},"description":"A Computer Science as profession and hobby. Firm believer of Software Engineering and a lover of Agile methodologies. There is no ring to rule them all, every place needs to forge its own master ring. His main field of experience is the Java ecosystem, and he has also worked actively with many related web technologies while looking to improve the client side of web applications.","sameAs":["http:\/\/acuriousanimal.com\/blog\/"],"url":"https:\/\/www.webcodegeeks.com\/author\/antonio-santiago\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/1111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=1111"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/1111\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/919"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=1111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=1111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=1111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}