I need to use/reuse a external (normal) function into the jQuery.each(), like this:
function foo(index,ele){
if(!($(ele).attr("href")) || $(ele).attr("href") == "") {
$(ele).addClass("yellow");
}
}
// INCORRECT, but WHY??
$("a").each(foo(index,domEle));
Here a jsfiddle example with correct and incorrect cases.
Because you’re passing the result of the function execution, not the function itself
in this case a reference to the function is passed and everything works as expected.
http://jsfiddle.net/zerkms/zTF22/1/