javascript - De-Anonymizing an Anonymous Function in jQuery -
this quite simple problem, it's causing me scratch head, i'm posting here.
i have jquery in following form:
if (jquery('.searchregions:checked').length == 0) { jquery('.searchregions').each(function(){ //code }); } else { jquery('.searchregions:checked').each(function(){ //the same code }); }
obviously seems ridiculous repeat big block of code inside each of these functions. when tried name , move function, seemed break down - perhaps because of issues scope and/or jquery(this) inside function no longer referring same object?
can me posting general idea of code should like? (or other optimisings or recastings make work appreciated!)
you can define function , use name:
function somehandler(event) { // code code code } jquery('.searchregions').each(somehandler);
note when refer function name, don't include "()".
Comments
Post a Comment