Despite the fact that you code is a bit of a mess, your problem is just that
since you aren't defining the variable "callback" with "var callback = ...",
it's being made a global variable, and as a global variable, each time you
call $(...).test1(...), you're overwriting "callback". Same for ttt. Adding
var before callback and ttt fixes the problem.
Good luck with it.
--Erik
On 10/24/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
>
> > You're not getting 'this' correct. Where you set 'b', 'this' is the
> > jQuery object, not an element. So 'b' is a jQuery object that wraps
> > three dom elements. Here's a hint:
> >
> > (function($) {
> > $.fn.test2 = function(color) {
> > // 'this' is the jQuery object
> > return this.each(function() {
> > // 'this' is a DOM element
> > var $el = $(this);
> > $el.bind('click', function() {
> > // this is the DOM element again
> > $el.css('color',color);
> > }
> > }
> > }
> >
> > })(jQuery);
>
> http://bynight.me.uk/jquery/mike.php
>
> Still its not okay, but...
>
> When I use
> b.bind('click', function() { b.css('color',color);}
> it works fine, but when I try:
>
> callback = function(data) {
> b.css('color',color);
> }
> ttt= function() {
> callback();
> }
> b.bind('click',ttt);
>
> I have result as you see on my page...
>
> ...
> To be more specific...
> I want use my plugin like that:
> callback = function() { ...}
> $('#something').test('option',callback);
> or $('#something').test('option',function() {...});
>
> thats why I want to have my function (ttt or callback) outside of
> b.bind(..)
>
> Thanks.
> Michael
>
>