jQuery Tip: How to Break Out of an .each() Loop

Here’s a nice little jQuery tip I found today.  If you want to break out of an each loop in jQuery, you can do it by returning false.

Here’s the real example from $().SPServices.SPArrangeChoices:

		$("td.ms-formbody").each(function() {
			if(searchText.test($(this).html())) {
				var radios = "<TR>";
				var choiceCount = 0;
				$(this).find("tr").each(function() {
					radios += $(this).html();
					if(choiceCount % opt.perRow == 0) radios += "</TR><TR>"
				radios += "</TR>";
				return false;

Tip ‘o the tam ‘o shanter to crad on tumblr for this one.

Have a thought or opinion?