Thursday, November 18, 2010

jQuery Plug-in API

The Great thing with jQuery is that programmers need not confine ourselves to built-in functionality too much. The plug-in API that is part of jQuery allows us to supplement the competences already present with new ones that suit application’s needs. Even in the small script we've written here, we've found use for a plug-in.
jQuery.fn.toggleNext = function() {
this.toggleClass('arrow-down')
.next().slideToggle('fast');
return this;
};

This code defines a new .toggleNext() jQuery method that slides the following element open and shut. You can now trigger new method later when needed.
$('#page-contents > a.toggler).click(function() {
$(this).toggleNext();
return false;
});

No comments:

Post a Comment