jQuery break out of each loop statement

While I was coding in jQuery, I bumped in a very unusual error, it’s about using a break statement inside an each loop statement.
Here’s my code:

jQuery("input:checkbox").each(function(index) {
   if( jQuery(this).attr("checked") == "checked" )
   {
     checked = "ischecked";
     break;
   }
});

I just thought this would be the same in PHP.

But after trying so hard :D , I got the solution.
Just replace the break; with return( false );

Here’s the code:

jQuery("input:checkbox").each(function(index) {
   if( jQuery(this).attr("checked") == "checked" )
   {
     checked = "ischecked";
     return( false );
   }
});

So this is how to break out of jQuery each statement
Hope this helps someone!

Have a happy coding! :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>