//Create a closed package(function($) { //definition of plug-in$.fn.hilight =function(Options) {Debug ( This); //build main options before element iteration varopts =$.extend ({}, $.fn.hilight.defaults, options); //iterate and reformat each matched element return This. each (function() { $ This= $( This); //build element Specific options varo = $.meta? $.extend ({}, opts, $ This. Data ()): opts; //Update element Styles$ This. css ({backgroundcolor:o.background, color:o.foreground}); varMarkup = $ This. html (); //Call our Format functionMarkup =$.fn.hilight.format (markup); $ This. HTML (markup); }); }; //Private Function: Debugging functionDebug ($obj) {if(Window.console &&window.console.log) Window.console.log (' Hilight selection count: ' +$obj. Size ()); }; //define the exposure format function$.fn.hilight.format =function(TXT) {return' <strong> ' + txt + ' </strong> '; }; //plug -in defaults$.fn.hilight.defaults ={foreground:' Red ', background:' Yellow ' }; // closing closure}) (JQuery);
jquery Plugin Sample Code