To make things easier to remember and apply, we are going to start off with the definition of what we will be referring to when speaking of the basic template that all the plugins we are going to develop should conform to.
Actually, we have already had a quick look at it earlier in the previous chapter, but there's something more definitely worth saying.
Note
From now on, we will call the following code the default structure for our plugins. This is what we will promptly copy and paste into each file we're going to write a plugin into.
jQuery.fn.PLUGINNAME = function() { return this.each(function() { // code }); }
Needless to say, the this.each
loop iterates all of the matching elements. We return the jQuery object (this
) to allow chaining. We extend the jQuery.fn
object; all of the code will be put inside the function.
Also:
The file name of every plugin we're going to develop will be
jquery.PLUGINNAME.js
.For the moment, remember to always avoid referring...