Skip to content

Instantly share code, notes, and snippets.

@stevenwadejr
Last active November 1, 2018 09:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenwadejr/6125219 to your computer and use it in GitHub Desktop.
Save stevenwadejr/6125219 to your computer and use it in GitHub Desktop.
Sometimes I want to execute some custom code while chaining on a jQuery element and maintain that chainability.
$.fn.chain = function(func) {
func.apply(this);
return this;
}
$('#my-div')
.fadeIn()
.chain(function(){
// Do something here
// You can even use $(this) on your original element
})
.fadeOut();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment