When using jQuery.each (), is it possible to use a non-anonymous function?

I have this block of code I find udnerstood particularly long and hard: the call stack is full of implicit functions and implicit paramters added to it. in other words, I would like to clarify my code by dividing the function called by each of them.

Take a look at this example:

$(xml).find('group').each(function () { var groupName = $(this).attr('name'); // There is here around 100 lines of codes I would like to split in // at least five functions, And I'm sure it is possible to use named functions // instead of implicit ones, no ? 
+6
source share
2 answers

Try the link function

Live demo

 $(xml).find('group').each(myfun); function myfun(i, item) { alert(item.id); } 
+4
source

You can also just do:

 $(xml).find('group').each(function(){ yourFunction(); }); 
+2
source

All Articles