views:

15

answers:

1

Help would be greatly appreciated. What is the correct markup that would change this function into a plugin. I tried, but cant make it to work.

$(document).ready(function(){
$('ul.tabNav a').click(function() {
var curChildIndex = $(this).parent().prevAll().length + 1;
$(this).parent().parent().children('.current').removeClass('current');
$(this).parent().addClass('current');
$(this).parent().parent().next('.tabContainer').children('.current').slideUp('fast',function() {
$(this).removeClass('current');
$(this).parent().children('div:nth-child('+curChildIndex+')').slideDown('normal',function() {
$(this).addClass('current');
});
});
return true;
});
});

A: 
 (function($) {

    jQuery.fn.pluginName = function() {  

             return this.each(function() {

                       Your Code;
      });
    };
 })(jQuery);
jimy
Thank you for this very clear answere. But how exactly do I call the plugin from within my html?
jaap Klevering
I found a simular question on this forum that answered my question. Thanks for your help. http://stackoverflow.com/questions/2157651/help-turning-jquery-script-into-a-plugin
jaap Klevering