Skip to content

Instantly share code, notes, and snippets.

@Hexodus
Created April 17, 2017 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hexodus/a68cef168d32635c53ab2f06f7492aac to your computer and use it in GitHub Desktop.
Save Hexodus/a68cef168d32635c53ab2f06f7492aac to your computer and use it in GitHub Desktop.
jQuery.fn.messagePlugin = function(){
var selectedObjects = this;
return {
saySomething : function(message){
$(selectedObjects).each(function(){
$(this).html(message);
});
return selectedObjects; // Preserve the jQuery chainability
},
anotherAction : function(){
//...
return selectedObjects;
}
};
}
// Usage:
$('p').messagePlugin().saySomething('I am a Paragraph').css('color', 'red');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment