jQuery Plugins jQuery.fn.extend() method


This method extends the jQuery prototype ($.fn) object to provide new custom methods that can be chained to the jQuery() function.

For example:

  // returns combination of div texts as a result
  getMessage: function() {
    var result;
    // this keyword corresponds result array of jquery selection
    this.each(function() {
        // $(this) corresponds each div element in this loop
        result = result + " " + $(this).val();
    return result;
// newly created .getMessage() method
var message = $("div").getMessage();

// message = Hello World!