how to exit outside the jQuery .each loop

jquery

Solution

You should use `return false`:

$(".hour").each(function() {
    if (want_to_break) {
        return false;
    }
});

Problem

Possible Duplicate: How to break/exit from a each() function in JQuery? I want to exit the jQuery `.each` loop on some condition, How can I do it. Will `exit;` code work? ``` var r = true; $('.hour').each(function() { var $hours = $(this).val(); if ($hours == "") { alert(" Active Time is required"); r = false; //exit; } }); return r; ```

Original source

Related problems