Hi
I'm trying to create plugin for jquery...
I have almost everything, but when Im using my plugin on more then one
elements then I have problem...

To show my problem I created this code:

(function($) {
        $.fn.extend({
                test2: function(color) {
                        var b=$(this);
                        return b.each(function() {
                                callback = function(data) {
                                        b.css('color',color);
                                }
                                ttt= function() {
                                        callback();
                                }
                                b.bind('click',ttt);
                        });
                }
        });
})(jQuery);

Then I have 3 elemets: <p id="aaa">..</p><p id="bbb">..</p><p
id="ccc">..</p>
I try to use my plugin in this way
$(document).ready(function() {
$('#aaa').test2('red');
$('#bbb').test2('green');
$('#ccc').test2('green');
}

But doesnt matter which <p> i click, always last element will change
color.

What Im doing wrong?

I need to have it like that instead of:
b.bind('click',function() {b.css('color',color);});

You can check this example on:
http://bynight.me.uk/jquery/


Thanks for help

Michael

Reply via email to