Performing same stuff to elements with different ids
by Annie Lagang
HTML
<ul>
<li id="item1">1</li>
<li id="item2">2</li>
<li id="item3">3</li>
</ul>
JavaScript
var ids = ["#item1", "#item2", "#item3"];
// option 1
//$(ids.join(',')).css('color', 'red');
// option 2
/*$(ids.join(',')).each(function(e) {
$(this).css('color', 'red');
});*/
// option 3
$.map(ids, function (elt, i) {
$(elt).css('color', 'red');
});
/*
ronically, the callback arguments used in the each method are the reverse of the callback arguments in the map function so be careful.
map(arr, function(elem, index) {});
// versus
each(arr, function(index, elem) {});
Another important thing to note is that the each function returns the original array while the map function returns a new array.
*/