Created
May 6, 2012 13:35
-
-
Save kesor/2622346 to your computer and use it in GitHub Desktop.
jQuery Each Slice loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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