Skip to content

Instantly share code, notes, and snippets.

@kesor
Created May 6, 2012 13:35
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 kesor/2622346 to your computer and use it in GitHub Desktop.
Save kesor/2622346 to your computer and use it in GitHub Desktop.
jQuery Each Slice loop
/* definition */
(function($){
$.fn.each_slice = function( iterator ) {
var index, objects;
objects = this;
for (index=0; index<=objects.length-1; index++) {
var single = objects.slice(index, index+1);
this = single;
iterator(single);
}
}
})( jQuery );
/* usage */
$('a.href').each_slice(function(){
this.attr( 'href', this.attr('href').concat('#foobar') );
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment