Skip to content

Instantly share code, notes, and snippets.

@karbassi
Created July 29, 2010 02:47
Show Gist options
  • Save karbassi/497093 to your computer and use it in GitHub Desktop.
Save karbassi/497093 to your computer and use it in GitHub Desktop.
$.fn.duplicate = function(count, cloneEvents, callback) {
var stack = [], el;
while(count--) {
el = this.clone( cloneEvents );
callback && callback.call(el);
stack.push( el.get()[0] );
}
return this.pushStack( stack );
};
@karbassi
Copy link
Author

So you can do:

$('<span\>', {text: 'I'm going, '}).duplicate(2, true, function(){ $(this).text('and going...') }).appendTo('body');

Output would be:

I'm going, and going.. and going..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment