1

I want to call this function (makes an element to blink), declared as a separate file:

(function($) {
$.fn.cyclicFade = function(options)
{
    if (typeof(options) == 'string') {
        if (options=='stop') {
            $(this).stop(true);
            return this.each(function() {
                $(this).data('cyclic-fade').enabled = false;
            });
        }
        else return null;
    }
    else {
        var opts = $.extend({}, $.fn.cyclicFade.defaults, options);
        return this.each(function() {
            $(this).data('cyclic-fade', {enabled : true});
            $.fn.cyclicFade.doCycle(this,1,opts.repeat,opts.params,0);
        });
    }
};
}

(it's not complete, space matters)

when I click a div called .swatch. How do I invoque the function?

$(document).ready(function() {
    $(".swatch").click(function () {
       // .swatch starts to blink
    }); 
});

Thanks in advance.

2 Answers 2

3
$(document).ready(function() {
  $(".swatch").click(function () {
    $(this).cyclicFade();
  }); 
});

this in the context of the function is the collection of elements matching the selector passed to $(...).

Sign up to request clarification or add additional context in comments.

2 Comments

Should also mention that $.fn.pluginName makes pluginName an extension of the jQuery object
Thanks a lot, I didn't think that was so easy.
1

Check this one:

$(this).cyclicFade();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.