Thanks, I see your point.. George.
On Nov 6, 7:28 am, "Alexandre Plennevaux" <[EMAIL PROTECTED]> wrote: > Hi Georges ! > > excellent way to learn. > > personally, i would use toggleClass() > (http://docs.jquery.com/Attributes/toggleClass#class) and have the > color set in the CSS file. As a rule, try always to use each > technology for what it was meant: > > html > data > css > styling > javascript > behaviour > > so it would be:http://jsbin.com/osaxa > > > > On Thu, Nov 6, 2008 at 6:46 AM, George <[EMAIL PROTECTED]> wrote: > > > Guys, I am learning JQuery (and JavaScript) in general. > > So I decided to write my first 'Blink' plug in. > > It works but can you please take a look an tell me if something is > > considered bad practice or can be done better. > > > (function($) { > > $.fn.blink = function(options) { > > var opts = $.extend({}, $.fn.blink.defaults, options); > > return this.each(function() { > > var $this = $(this); > > var currentColor = opts.color1; > > > $this.css({backgroundColor: currentColor}); > > window.setInterval(function (){DoTheBlink();}, > > 1000); > > function DoTheBlink() > > { > > if (currentColor == opts.color1) > > currentColor = opts.color2; > > else > > currentColor = opts.color1; > > $this.css({ backgroundColor: currentColor }); > > } > > }); > > }; > > > $.fn.blink.defaults = { > > color1: 'red', > > color2: 'blue' > > }; > > })(jQuery); > > > --------------USE------------- > > <div id=t1>hahaha</div> > > <div id=t2>hahaha</div> > > <div id=t3>hahaha</div> > > <script> > > $(document).ready(function() { > > > $('#t1').blink({ color1: 'red', color2:'blue' }); > > $('#t2').blink({ color1: 'yellow', color2:'black' }); > > $('#t3').blink({ color1: 'red', color2:'green' }); > > }); > > > Thanks > > George.- Hide quoted text - > > - Show quoted text -