{"id":1110,"date":"2014-10-11T20:00:57","date_gmt":"2014-10-11T17:00:57","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=1110"},"modified":"2014-10-11T17:53:29","modified_gmt":"2014-10-11T14:53:29","slug":"things-i-learnt-creating-a-jquery-plugin-part-i","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/","title":{"rendered":"Things I learnt creating a jQuery Plugin (Part I)"},"content":{"rendered":"<p><a href=\"http:\/\/jquery.com\/\" target=\"_blank\">jQuery<\/a> is one of the most used JavaScript libraries, if not the most used one, which allows to make great things with the big set of little tools it offers to the web developers: HTML\/DOM manipulation, CSS manipulation, HTML event methods, effects and animations, AJAX, utilities, \u2026<\/p>\n<p>One of the key aspects of jQuery is the possibility to extend it with new\u00a0functionalities, so called <em>plugins<\/em>. For those who has a basic knowledge of jQuery and want or need to create a new jQuery plugin this post tries to be a helping summary of good things to take into account.<\/p>\n<p>&nbsp;<\/p>\n<h2>Before to start<\/h2>\n<p>Because of the flexibility and powerful of the language, the Perl community is proud of his <em>Tim Today<\/em> motto, \u00a0that is:<\/p>\n<blockquote><p><strong><span style=\"color: #339966;\">There\u2019s more than one way to do it<\/span><\/strong><\/p><\/blockquote>\n<p>You can consider the same for JavaScript, that\u2019s true. The fact JavaScript is not an object oriented language but a <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/JavaScript\/Introduction_to_Object-Oriented_JavaScript#Prototype-based_programming\" target=\"_blank\">prototype based language<\/a> allows to follow the OOP paradigm in many different ways. Looking for a template code to create a jQuery plugin I found tons and not all following the same conventions and ideas.<\/p>\n<p>Here I present a mix of the most accepted templates and its key aspects.<\/p>\n<h2>The code<\/h2>\n<p>Accompanying the article you can find\u00a0the self documented version of the boilerplate code at my <a href=\"https:\/\/github.com\/acanimal\/jQuery-Plugin-Boilerplate\" target=\"_blank\">GitHub repository<\/a>.<\/p>\n<h2>Where to start<\/h2>\n<p>If you are planning to create a jQuery plugin, the first places I suggest you to start reading is the <a href=\"http:\/\/docs.jquery.com\/Plugins\/Authoring\" target=\"_blank\">Plugins\/Authoring<\/a> section of the project documentation. It is a great starting resource but in the real live you will find soon you need to know a bit more of that.<\/p>\n<h2>Using a jQuery plugin<\/h2>\n<p>Suppose we have a jQuery plugin called <code>beautyLink<\/code>, that transform a normal link (the <code>&lt;a&gt;<\/code> element) into a really nice one changing the font family, text and background color. So we need to include it in our page before start using it:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;jquery.js&quot;&gt;&lt;\/script&gt;\r\n&lt;script type=&quot;text\/javascript&quot; src=&quot;jquery-beautylink.js&quot;&gt;&lt;\/script&gt; <\/pre>\n<p>The conventional way to create and apply it on an element would be:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#linkID').beautyLink();<\/pre>\n<p>or, if you want to apply on each link of the current page:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('a').beautyLink();<\/pre>\n<p>Later, to change the text color to red we could invoke a plugin\u2019s public method like:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#linkID').beautyLink('color', 'red');<\/pre>\n<p>or to retrieve the current text color:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#linkID').beautyLink('color');<\/pre>\n<p>that is, the <code>color<\/code> method can act as a setter or getter depending if we pass a value or not.<\/p>\n<h2>Creating a new plugin<\/h2>\n<p>All right, we know how to use a plugin but we want to create a new one. The first step we need to do is to create a new JavaScript file where to place our code. As a good practice this file must contain a documentation header section with the plugin\u2019s name, version, author contact information, license, etc<\/p>\n<p>When we include the JavaScript file in a web page we need the code to be auto-executed so the plugin can be registered within the jQuery. To do so all the JavaScript code in the file must be inside the code:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n(function($, window, document, undefined) {\r\n  \/\/ The code here\r\n})(jQuery, window, document);<\/pre>\n<p>This way, the code of our plugin will receive a reference to the jQuery library, the window and the document and, also, an undefined reference on the <code>undefined<\/code>parameter that we can use to compare undefined values (wow, that was too much undefineds in a sentence).<\/p>\n<h2>The wrapper function<\/h2>\n<p>To create a jQuery plugin we need to register a new function in the <code>jQuery.fn<\/code> object. This is an array where jQuery stores references to all available or included plugins in the current page. To add a new one simply write something like:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\njQuery.fn.myPlugin = function(options) {\r\n  \/\/ Do your awesome plugin stuff here\r\n};<\/pre>\n<p>or<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\njQuery.fn&#x5B;'myPlugin'] = function(options) {\r\n  \/\/ Do your awesome plugin stuff here\r\n};<\/pre>\n<p><strong>The function you define here is the entry point to your plugin. It is a wrapper function that must handle the plugins initialization or\u00a0invocation\u00a0to any plugin\u2019s method.<\/strong><\/p>\n<h3>How to distinguish the action?<\/h3>\n<p>The question is, how do we implement the plugin\u2019s wrapper function to distinguish if it must initialize the plugin or call a method? The answer is in the <code>options<\/code> parameter.<\/p>\n<p>When we instantiate a plugin without passing any argument the <code>options<\/code> parameter is<code>undefined<\/code>:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#linkID').beautyLink();<\/pre>\n<p>If we instantiate passing any argument the <code>options<\/code> parameter is an <code>Object<\/code>:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#linkID').beautyLink({\r\n  someOption: 'a',\r\n  someOther: 123\r\n});<\/pre>\n<p>Finally, if we are calling a plugin\u2019s method like:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#linkID').beautyLink('color', 'red');<\/pre>\n<p>then the <code>options<\/code> parameter is an array with two elements <code>['color', 'red']<\/code><\/p>\n<h2>The starter code for the wrapper function<\/h2>\n<p>With the above in mind, we can write the base code for the wrapper function:<\/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\r\n\r\n    } else if (typeof options === 'string' &amp;amp;&amp;amp; options&#x5B;0] !== '_' &amp;amp;&amp;amp; options !== 'init') {\r\n        \/\/ Call a public pluguin method (not starting with an underscore) and different\r\n        \/\/ from the 'init' one\r\n\r\n    }\r\n};<\/pre>\n<h2>Chainable or not chainable<\/h2>\n<p>jQuery is famous (and powerful) by its chainable way to work, that is, a call to a method returns a reference to the same element so we can make another call. For example:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#someID')\r\n  .parents(&quot;.pane&quot;)\r\n  .animate({ opacity: &quot;hide&quot; }, &quot;slow&quot;);<\/pre>\n<p>or applied to our plugin:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#linkID')\r\n  .beautyLink('color', 'red')\r\n  .beautyLink('backgroundColor', 'black');<\/pre>\n<p>We must think which of our methods must be chainable and which ones not. For example, <strong>the getter methods must break the chainability<\/strong>. In our case we want a call to:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#linkID').beautyLink('color');<\/pre>\n<p>returns the <code>red<\/code> value and not a reference to the element to make another call.<\/p>\n<h3>Implementing chainability<\/h3>\n<p>When the wrapper function <code>$.fn[pluginName]<\/code> is called the this reference points to:<\/p>\n<ul>\n<li>the selected DOM element, like when using:<\/li>\n<\/ul>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('#linkID').beautyLink('color', 'red');<\/pre>\n<p>or<\/p>\n<ul>\n<li>a list of selected DOM elements, like when using:<\/li>\n<\/ul>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$('a').beautyLink('color', 'red');<\/pre>\n<p>Next code shows a very basic wrapper function that initializes a Plugin instance for each selected element. This results in a chainable call that returns a reference to the same element ready to make another chained call:<\/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>Avoiding chainability<\/h3>\n<p>The solution to avoid a method were chainable is easy, simply doesn\u2019t write the<code>this.each()<\/code> and execute code on the first occurrence, that is, the <code>this[0]<\/code>.<\/p>\n<blockquote><p><span style=\"color: #339966;\"><strong>This will be more clear in the final code.<\/strong><\/span><\/p><\/blockquote>\n<h2>The jQuery.data() function<\/h2>\n<p>We make use of the <code>$.data()<\/code> function in our code so a short explanation is required.<br \/>\nThe <a href=\"http:\/\/api.jquery.com\/jQuery.data\/\" target=\"_blank\"><code>$.data()<\/code><\/a> function allows to store arbitrary data on an element (or get is value).<\/p>\n<p>It is important because we store a reference to the Plugin instance on each element it is applied. This allow us to check if an element has already applied a plugin or we need to instantiate it. This will be clarified in the final wrapper function code.<\/p>\n<h2>The backbone wrapper function code<\/h2>\n<p>With all the above in mind, we can write our final plugin\u2019s wrapper function. To summarize:<\/p>\n<ul>\n<li>If plugin is called without arguments, then the plugin is initialized and a reference is stored in the DOM element.<\/li>\n<li>If a plugin\u2019s method is called and it isn\u2019t a getter method, then the method is called maintaining chainability.<\/li>\n<li>If a plugin\u2019s method is called and it is a getter method, then we return a value and break the chainability.<\/li>\n<\/ul>\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    } else if (typeof options === 'string' &amp;amp;&amp;amp; options&#x5B;0] !== '_' &amp;amp;&amp;amp; options !== 'init') {\r\n        \/\/ Call a public pluguin method (not starting with an underscore) for each\r\n        \/\/ selected element.\r\n        if (Array.prototype.slice.call(args, 1).length == 0 &amp;amp;&amp;amp; $.inArray(options, $.fn&#x5B;pluginName].getters) != -1) {\r\n            \/\/ If the user does not pass any arguments and the method allows to\r\n            \/\/ work as a getter then break the chainability so we can return a value\r\n            \/\/ instead the element reference.\r\n            var instance = $.data(this&#x5B;0], 'plugin_' + pluginName);\r\n            return instance&#x5B;options].apply(instance, Array.prototype.slice.call(args, 1));\r\n        } else {\r\n            \/\/ Invoke the speficied method on each selected element\r\n            return this.each(function() {\r\n                var instance = $.data(this, 'plugin_' + pluginName);\r\n                if (instance instanceof Plugin &amp;amp;&amp;amp; typeof instance&#x5B;options] === 'function') {\r\n                    instance&#x5B;options].apply(instance, Array.prototype.slice.call(args, 1));\r\n                }\r\n            });\r\n        }\r\n    }\r\n};<\/pre>\n<p>Take into account, we have also defined an array where to specify which method can act as getters when they are invoked without any argument:<\/p>\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n$.fn&#x5B;pluginName].getters = &#x5B;'someGetterMethod'];<\/pre>\n<h2>To be continued&#8230;<\/h2>\n<p>We have seen the basis on how to create a jQuery plugin and learnt about the importance of the wrapper function, which is the entry point to our plugin.<br \/>\nIn the next post I will explain how we can organize our plugin code, the responsible to implement functionality, how to create private and public method, etc.<\/p>\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\/01\/15\/things-i-learned-creating-a-jquery-plugin-part-i\/\">Things I learnt creating a jQuery Plugin (Part I)<\/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>jQuery is one of the most used JavaScript libraries, if not the most used one, which allows to make great things with the big set of little tools it offers to the web developers: HTML\/DOM manipulation, CSS manipulation, HTML event methods, effects and animations, AJAX, utilities, \u2026 One of the key aspects of jQuery is &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-1110","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 learnt creating a jQuery Plugin (Part I) - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"jQuery is one of the most used JavaScript libraries, if not the most used one, which allows to make great things with the big set of little tools it\" \/>\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-learnt-creating-a-jquery-plugin-part-i\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Things I learnt creating a jQuery Plugin (Part I) - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"jQuery is one of the most used JavaScript libraries, if not the most used one, which allows to make great things with the big set of little tools it\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/\" \/>\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-11T17:00:57+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=\"8 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-learnt-creating-a-jquery-plugin-part-i\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/\"},\"author\":{\"name\":\"Antonio Santiago\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b9ad428a9312fc720bef9ebc43421e78\"},\"headline\":\"Things I learnt creating a jQuery Plugin (Part I)\",\"datePublished\":\"2014-10-11T17:00:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/\"},\"wordCount\":1589,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#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-learnt-creating-a-jquery-plugin-part-i\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/\",\"name\":\"Things I learnt creating a jQuery Plugin (Part I) - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg\",\"datePublished\":\"2014-10-11T17:00:57+00:00\",\"description\":\"jQuery is one of the most used JavaScript libraries, if not the most used one, which allows to make great things with the big set of little tools it\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#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-learnt-creating-a-jquery-plugin-part-i\/#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 learnt creating a jQuery Plugin (Part I)\"}]},{\"@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 learnt creating a jQuery Plugin (Part I) - Web Code Geeks - 2026","description":"jQuery is one of the most used JavaScript libraries, if not the most used one, which allows to make great things with the big set of little tools it","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-learnt-creating-a-jquery-plugin-part-i\/","og_locale":"en_US","og_type":"article","og_title":"Things I learnt creating a jQuery Plugin (Part I) - Web Code Geeks - 2026","og_description":"jQuery is one of the most used JavaScript libraries, if not the most used one, which allows to make great things with the big set of little tools it","og_url":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2014-10-11T17:00:57+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":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/"},"author":{"name":"Antonio Santiago","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/b9ad428a9312fc720bef9ebc43421e78"},"headline":"Things I learnt creating a jQuery Plugin (Part I)","datePublished":"2014-10-11T17:00:57+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/"},"wordCount":1589,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#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-learnt-creating-a-jquery-plugin-part-i\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/","url":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/","name":"Things I learnt creating a jQuery Plugin (Part I) - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/10\/jquery-logo.jpg","datePublished":"2014-10-11T17:00:57+00:00","description":"jQuery is one of the most used JavaScript libraries, if not the most used one, which allows to make great things with the big set of little tools it","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/javascript\/jquery\/things-i-learnt-creating-a-jquery-plugin-part-i\/#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-learnt-creating-a-jquery-plugin-part-i\/#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 learnt creating a jQuery Plugin (Part I)"}]},{"@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\/1110","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=1110"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/1110\/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=1110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=1110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=1110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}