Skip to content
This repository has been archived by the owner on Oct 27, 2019. It is now read-only.

subtleGradient/MooTools-Elements.SetEach

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Elements.SetEach

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

Notice

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

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


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


$$('a').setEach('html',[
    "New foo HTML!",
    function(html){ return html + ' appended moar foo!'; },
    replaceFooWithBar,
    function(html,i){ return html + ' Index is ' + i; }
	
]);


$$('a').setEachStyle({
    '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('');
    }
});

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published