Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

44 lines (32 sloc) 1.124 kb


Pass a callback function to set one or many values on every element in an Elements collection.


Only works with an Elements collection, usually gotten by using $$.

This will not work with individual elements. e.g. $('myid').setEach() will throw an error. Use $$('#myid').setEach() instead.

How to Use

function replaceFooWithBar(string){
    return String(string).replace(/\bfoo\b/g,'bar');

$$('a').setEach('href', function(currentHref, i){
    return currentHref + '?foo=bar';

    "New foo HTML!",
    function(html){ return html + ' appended moar foo!'; },
    function(html,i){ return html + ' Index is ' + i; }


    'color': function(currentColor, i) {
        i = i.toString(16);
        return ['#', i, i, i].join('');
    'background-color': function(currentColor, i) {
        i = (15 - i).toString(16);
        return['#', i, i, i].join('');
Jump to Line
Something went wrong with that request. Please try again.