How do you create a jQuery plugin?

<p class="a">One</p><p class="a">Two</p>
$.fn.markAs = function (options) {
  var settings = $.extend({ label: 'done' }, options);
  return this.each(function () {
    $(this).addClass(settings.label);
  });
};

$('.a').markAs({ label: 'checked' });
HTML after the code runs

<p class="a checked">One</p>
<p class="a checked">Two</p>

See jQuery Plugins.


Learn more about the similar topics:
Tutorials
jQuery each() and map()
jQuery Utility Methods
jQuery Plugins
Exercises & Assignments
Write a simple jQuery plugin to highlight elements
Interview Questions & Answers
How do you loop over elements with jQuery each()?
How do you create a jQuery plugin?