Elements.setEach 1.0

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



Details

Author
Thomas Aylott
Current version
1.0
GitHub
subtleGradient/MooTools-Elements.SetEach
Downloads
1608
Category
Utilities
Tags
Report
GitHub Issues

Releases


Dependencies

  • _self_/_current_:
    • core/1.2.4: $util
    • core/1.2.4: Array
    • core/1.2.4: Elements

How to use

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('');
    }
});

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.


Discuss

A note on comments here: These comments are moderated. No comments will show up until they are approved. Comments that are not productive (i.e. inflammatory, rude, etc) will not be approved.

Found a bug in this plugin? Please report it this repository's Github Issues.

blog comments powered by Disqus