how to return true/false from nested jquery callback functions

javascript, jquery, jquery-plugins, jquery-ui

Solution

I think this is what you're looking for, this will stop both loops when the `true` condition is met

function validate(key) {
    var result = false;
    $jquery.each(function(){
        $jquery.each(function(){
            if(){
                result = true;
                return false;//break inner loop
            }
        });
        if(result)
            return false; //break outer loop if we got true in inner
    });
    return result;
}

Demo fiddle You can open your console and see that the loop stops when the true condition is met

Problem

I am trying to validate elements inside a javascript function which contains two jQuery callback loops. Based on the conditions I want to return `true`/`false` from the inner jQuery loop and that should be sent back to the calling method of javascript. If the result of the inner loop is `true` the loop should stop running. ``` if(validate(key)){ } else{ } function validate(key) { $jquery.each(function(){ $jquery.each(function(){ if(){ return true; } else{ return false} }) }) } ```

Original source