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);Written by Jan Dudulski
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Each
Authors
jandudulski
1.647K
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#