jQuery: How to Create a Basic Plugin
(function ( $ ) {
$.fn.greenify = function( options ) {
// This is the easiest way to have default options.
var settings = $.extend({
// These are the defaults.
color: “#556b2f”,
backgroundColor: “white”
}, options );// Greenify the collection based on the settings variable.
return this.css({
color: settings.color,
backgroundColor: settings.backgroundColor
});};
}( jQuery ));
$( "div" ).greenify({
color: "orange"
});