Write a tiny jQuery plugin
Add your own method to $.fn. Return this so calls can be chained.
jQuery · Write a tiny jQuery pluginIntermediate
(function ($) {
$.fn.highlight = function (color) {
return this.each(function () {
$(this).css('background-color', color || 'yellow');
});
};
})(jQuery);
$('p.note').highlight('#ffd').addClass('done');plugin$.fnchainablereuse