I have the following form
<input class="required" id="name" value="some content"/>
<input class="required" id="address" value=""/>
<input class="required" id="lastname" value="some content"/>
and the following jQuery function. It contains a .each() loop to check some inputs. When the check fails, the function should break and return false.
function check() {
$('.required').each(function() {
var input = $(this);
console.log(input.attr('id'));
if (input.val() == null || input.val() == '') {
console.log('*** Failed ***');
return false;
}
});
console.log('Other code');
return true;
}
Unfortunately, when I run the code I see the following output:
name
address
*** Failed ***
Other code
The .each() loop correctly stops after the first failure, but the check function seems to keep running. How can I break its execution? Here's a jsFiddle.
falsefrom each anonymous function, not fromcheck()