discuss  

Re: [jQuery] how to stop each iteration under each's function?

Mark Gibson
Tue, 31 Oct 2006 05:21:49 -0800

asterocean wrote:
> for exzample:
>  
> $("[EMAIL PROTECTED]'text']").each(function(){if 
> (this.value==""){alert("error");this.focus();break;}});
>  
> but 'break;' won't stop the iteration of each, what should i do?

There was some discussion on this list of returning false
to break the loop - but I'm not sure if that has been
implemented yet - does anyone know?

$("[EMAIL PROTECTED]'text']").each(function() {
     if (this.value=="") {
         alert("error"); this.focus();
         return false;
     }
});

Otherwise, you can throw an exception:

try {
     $("[EMAIL PROTECTED]'text']").each(function() {
         if (this.value=="") {
             alert("error"); this.focus();
             throw true; // The actual value here is arbitary
         }
     });
} catch(e) {}

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/