Last Updated: September 09, 2019
·
1.476K
· jandudulski

Shorter $.each

In most cases when you are going to use $.each method you just want to call simple function on each element of the set.

In such cases instead of:

$('.nice-class').each(function(index, Element) {
  Element.doSmth();
});

You can just write:

$('.nice-class').each(doSmth);

Examples?

var hide_it = function() { $(this).hide(); };
$('[data-hidden]').each(hide_it);