What you have to do is actually *call* the callback function.

Now the way you've written the callback, it expects 'this' to be the element
you're working on - the same element which is 'this' in the click handler
itself. So you can't use an ordinary function call, you have to use .call()
or .apply().

You might change the code inside your click function to:

                               alert(val);
                               callback.call(this);
                               return false;

That will alert the value and then call the callback, with 'this' in the
callback set to the same element that it is set to in the click handler. You
can pass additional arguments to the callback by listing them after 'this'
in that call.

-Mike

On Sat, Oct 10, 2009 at 2:51 PM, kknaru <isai...@gmail.com> wrote:

>
> i know that load accepts a callback, but i want to understand how to
> write a function that accepts a callback function 'cause i want to use
> it in a plugin. I'm new to plugin development so this are my first
> steps in understanding this concepts.
>
> ok, so i tried a simple script just to understand how it works. so on
> anchor click i want to pop an alert message with the value specified
> in function arguments and as a callback i want to increase the font
> size...but...i don;t really get it. some help will be appreciated :)
>
> so i have this:
>
> (function($){
>        $.fn.extend({
>                //function name
>                itPops : function(value,callback){
>                //return
>                return this.each(function(){
>                        var val = value;
>                        $(this).click(function(){
>                                alert(val);
>                                return false;
>                        })
>                })
>                }
>        });
> })(jQuery);
>
>
> $(document).ready(function(){
>        $('a').itPops(2,function(){
>                $(this).css({'font-size':'23px'});
>        });
> });
>
>
> so...can you shoe me pls on my code how should i do with that
> callback? many thanks
>

Reply via email to